prolog_highlight_rules.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2012, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /* This file was autogenerated from https://raw.github.com/stephenroller/prolog-tmbundle/master/Syntaxes/Prolog.tmLanguage (uuid: ) */
  31. /****************************************************************************************
  32. * IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
  33. * fileTypes *
  34. ****************************************************************************************/
  35. define(function(require, exports, module) {
  36. "use strict";
  37. var oop = require("../lib/oop");
  38. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  39. var PrologHighlightRules = function() {
  40. // regexp must not have capturing parentheses. Use (?:) instead.
  41. // regexps are ordered -> the first match is used
  42. this.$rules = { start:
  43. [ { include: '#comment' },
  44. { include: '#basic_fact' },
  45. { include: '#rule' },
  46. { include: '#directive' },
  47. { include: '#fact' } ],
  48. '#atom':
  49. [ { token: 'constant.other.atom.prolog',
  50. regex: '\\b[a-z][a-zA-Z0-9_]*\\b' },
  51. { token: 'constant.numeric.prolog',
  52. regex: '-?\\d+(?:\\.\\d+)?' },
  53. { include: '#string' } ],
  54. '#basic_elem':
  55. [ { include: '#comment' },
  56. { include: '#statement' },
  57. { include: '#constants' },
  58. { include: '#operators' },
  59. { include: '#builtins' },
  60. { include: '#list' },
  61. { include: '#atom' },
  62. { include: '#variable' } ],
  63. '#basic_fact':
  64. [ { token:
  65. [ 'entity.name.function.fact.basic.prolog',
  66. 'punctuation.end.fact.basic.prolog' ],
  67. regex: '([a-z]\\w*)(\\.)' } ],
  68. '#builtins':
  69. [ { token: 'support.function.builtin.prolog',
  70. regex: '\\b(?:abolish|abort|ancestors|arg|ascii|assert[az]|atom(?:ic)?|body|char|close|conc|concat|consult|define|definition|dynamic|dump|fail|file|free|free_proc|functor|getc|goal|halt|head|head|integer|length|listing|match_args|member|next_clause|nl|nonvar|nth|number|cvars|nvars|offset|op|print?|prompt|putc|quoted|ratom|read|redefine|rename|retract(?:all)?|see|seeing|seen|skip|spy|statistics|system|tab|tell|telling|term|time|told|univ|unlink_clause|unspy_predicate|var|write)\\b' } ],
  71. '#comment':
  72. [ { token:
  73. [ 'punctuation.definition.comment.prolog',
  74. 'comment.line.percentage.prolog' ],
  75. regex: '(%)(.*$)' },
  76. { token: 'punctuation.definition.comment.prolog',
  77. regex: '/\\*',
  78. push:
  79. [ { token: 'punctuation.definition.comment.prolog',
  80. regex: '\\*/',
  81. next: 'pop' },
  82. { defaultToken: 'comment.block.prolog' } ] } ],
  83. '#constants':
  84. [ { token: 'constant.language.prolog',
  85. regex: '\\b(?:true|false|yes|no)\\b' } ],
  86. '#directive':
  87. [ { token: 'keyword.operator.directive.prolog',
  88. regex: ':-',
  89. push:
  90. [ { token: 'meta.directive.prolog', regex: '\\.', next: 'pop' },
  91. { include: '#comment' },
  92. { include: '#statement' },
  93. { defaultToken: 'meta.directive.prolog' } ] } ],
  94. '#expr':
  95. [ { include: '#comments' },
  96. { token: 'meta.expression.prolog',
  97. regex: '\\(',
  98. push:
  99. [ { token: 'meta.expression.prolog', regex: '\\)', next: 'pop' },
  100. { include: '#expr' },
  101. { defaultToken: 'meta.expression.prolog' } ] },
  102. { token: 'keyword.control.cutoff.prolog', regex: '!' },
  103. { token: 'punctuation.control.and.prolog', regex: ',' },
  104. { token: 'punctuation.control.or.prolog', regex: ';' },
  105. { include: '#basic_elem' } ],
  106. '#fact':
  107. [ { token:
  108. [ 'entity.name.function.fact.prolog',
  109. 'punctuation.begin.fact.parameters.prolog' ],
  110. regex: '([a-z]\\w*)(\\()(?!.*:-)',
  111. push:
  112. [ { token:
  113. [ 'punctuation.end.fact.parameters.prolog',
  114. 'punctuation.end.fact.prolog' ],
  115. regex: '(\\))(\\.?)',
  116. next: 'pop' },
  117. { include: '#parameter' },
  118. { defaultToken: 'meta.fact.prolog' } ] } ],
  119. '#list':
  120. [ { token: 'punctuation.begin.list.prolog',
  121. regex: '\\[(?=.*\\])',
  122. push:
  123. [ { token: 'punctuation.end.list.prolog',
  124. regex: '\\]',
  125. next: 'pop' },
  126. { include: '#comment' },
  127. { token: 'punctuation.separator.list.prolog', regex: ',' },
  128. { token: 'punctuation.concat.list.prolog',
  129. regex: '\\|',
  130. push:
  131. [ { token: 'meta.list.concat.prolog',
  132. regex: '(?=\\s*\\])',
  133. next: 'pop' },
  134. { include: '#basic_elem' },
  135. { defaultToken: 'meta.list.concat.prolog' } ] },
  136. { include: '#basic_elem' },
  137. { defaultToken: 'meta.list.prolog' } ] } ],
  138. '#operators':
  139. [ { token: 'keyword.operator.prolog',
  140. regex: '\\\\\\+|\\bnot\\b|\\bis\\b|->|[><]|[><\\\\:=]?=|(?:=\\\\|\\\\=)=' } ],
  141. '#parameter':
  142. [ { token: 'variable.language.anonymous.prolog',
  143. regex: '\\b_\\b' },
  144. { token: 'variable.parameter.prolog',
  145. regex: '\\b[A-Z_]\\w*\\b' },
  146. { token: 'punctuation.separator.parameters.prolog', regex: ',' },
  147. { include: '#basic_elem' },
  148. { token: 'text', regex: '[^\\s]' } ],
  149. '#rule':
  150. [ { token: 'meta.rule.prolog',
  151. regex: '(?=[a-z]\\w*.*:-)',
  152. push:
  153. [ { token: 'punctuation.rule.end.prolog',
  154. regex: '\\.',
  155. next: 'pop' },
  156. { token: 'meta.rule.signature.prolog',
  157. regex: '(?=[a-z]\\w*.*:-)',
  158. push:
  159. [ { token: 'meta.rule.signature.prolog',
  160. regex: '(?=:-)',
  161. next: 'pop' },
  162. { token: 'entity.name.function.rule.prolog',
  163. regex: '[a-z]\\w*(?=\\(|\\s*:-)' },
  164. { token: 'punctuation.rule.parameters.begin.prolog',
  165. regex: '\\(',
  166. push:
  167. [ { token: 'punctuation.rule.parameters.end.prolog',
  168. regex: '\\)',
  169. next: 'pop' },
  170. { include: '#parameter' },
  171. { defaultToken: 'meta.rule.parameters.prolog' } ] },
  172. { defaultToken: 'meta.rule.signature.prolog' } ] },
  173. { token: 'keyword.operator.definition.prolog',
  174. regex: ':-',
  175. push:
  176. [ { token: 'meta.rule.definition.prolog',
  177. regex: '(?=\\.)',
  178. next: 'pop' },
  179. { include: '#comment' },
  180. { include: '#expr' },
  181. { defaultToken: 'meta.rule.definition.prolog' } ] },
  182. { defaultToken: 'meta.rule.prolog' } ] } ],
  183. '#statement':
  184. [ { token: 'meta.statement.prolog',
  185. regex: '(?=[a-z]\\w*\\()',
  186. push:
  187. [ { token: 'punctuation.end.statement.parameters.prolog',
  188. regex: '\\)',
  189. next: 'pop' },
  190. { include: '#builtins' },
  191. { include: '#atom' },
  192. { token: 'punctuation.begin.statement.parameters.prolog',
  193. regex: '\\(',
  194. push:
  195. [ { token: 'meta.statement.parameters.prolog',
  196. regex: '(?=\\))',
  197. next: 'pop' },
  198. { token: 'punctuation.separator.statement.prolog', regex: ',' },
  199. { include: '#basic_elem' },
  200. { defaultToken: 'meta.statement.parameters.prolog' } ] },
  201. { defaultToken: 'meta.statement.prolog' } ] } ],
  202. '#string':
  203. [ { token: 'punctuation.definition.string.begin.prolog',
  204. regex: '\'',
  205. push:
  206. [ { token: 'punctuation.definition.string.end.prolog',
  207. regex: '\'',
  208. next: 'pop' },
  209. { token: 'constant.character.escape.prolog', regex: '\\\\.' },
  210. { token: 'constant.character.escape.quote.prolog',
  211. regex: '\'\'' },
  212. { defaultToken: 'string.quoted.single.prolog' } ] } ],
  213. '#variable':
  214. [ { token: 'variable.language.anonymous.prolog',
  215. regex: '\\b_\\b' },
  216. { token: 'variable.other.prolog',
  217. regex: '\\b[A-Z_][a-zA-Z0-9_]*\\b' } ] }
  218. this.normalizeRules();
  219. };
  220. PrologHighlightRules.metaData = { fileTypes: [ 'plg', 'prolog' ],
  221. foldingStartMarker: '(%\\s*region \\w*)|([a-z]\\w*.*:- ?)',
  222. foldingStopMarker: '(%\\s*end(\\s*region)?)|(?=\\.)',
  223. keyEquivalent: '^~P',
  224. name: 'Prolog',
  225. scopeName: 'source.prolog' }
  226. oop.inherits(PrologHighlightRules, TextHighlightRules);
  227. exports.PrologHighlightRules = PrologHighlightRules;
  228. });