mode-prolog.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. define("ace/mode/prolog_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  2. "use strict";
  3. var oop = ace_require("../lib/oop");
  4. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  5. var PrologHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { include: '#comment' },
  8. { include: '#basic_fact' },
  9. { include: '#rule' },
  10. { include: '#directive' },
  11. { include: '#fact' } ],
  12. '#atom':
  13. [ { token: 'constant.other.atom.prolog',
  14. regex: '\\b[a-z][a-zA-Z0-9_]*\\b' },
  15. { token: 'constant.numeric.prolog',
  16. regex: '-?\\d+(?:\\.\\d+)?' },
  17. { include: '#string' } ],
  18. '#basic_elem':
  19. [ { include: '#comment' },
  20. { include: '#statement' },
  21. { include: '#constants' },
  22. { include: '#operators' },
  23. { include: '#builtins' },
  24. { include: '#list' },
  25. { include: '#atom' },
  26. { include: '#variable' } ],
  27. '#basic_fact':
  28. [ { token:
  29. [ 'entity.name.function.fact.basic.prolog',
  30. 'punctuation.end.fact.basic.prolog' ],
  31. regex: '([a-z]\\w*)(\\.)' } ],
  32. '#builtins':
  33. [ { token: 'support.function.builtin.prolog',
  34. 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' } ],
  35. '#comment':
  36. [ { token:
  37. [ 'punctuation.definition.comment.prolog',
  38. 'comment.line.percentage.prolog' ],
  39. regex: '(%)(.*$)' },
  40. { token: 'punctuation.definition.comment.prolog',
  41. regex: '/\\*',
  42. push:
  43. [ { token: 'punctuation.definition.comment.prolog',
  44. regex: '\\*/',
  45. next: 'pop' },
  46. { defaultToken: 'comment.block.prolog' } ] } ],
  47. '#constants':
  48. [ { token: 'constant.language.prolog',
  49. regex: '\\b(?:true|false|yes|no)\\b' } ],
  50. '#directive':
  51. [ { token: 'keyword.operator.directive.prolog',
  52. regex: ':-',
  53. push:
  54. [ { token: 'meta.directive.prolog', regex: '\\.', next: 'pop' },
  55. { include: '#comment' },
  56. { include: '#statement' },
  57. { defaultToken: 'meta.directive.prolog' } ] } ],
  58. '#expr':
  59. [ { include: '#comments' },
  60. { token: 'meta.expression.prolog',
  61. regex: '\\(',
  62. push:
  63. [ { token: 'meta.expression.prolog', regex: '\\)', next: 'pop' },
  64. { include: '#expr' },
  65. { defaultToken: 'meta.expression.prolog' } ] },
  66. { token: 'keyword.control.cutoff.prolog', regex: '!' },
  67. { token: 'punctuation.control.and.prolog', regex: ',' },
  68. { token: 'punctuation.control.or.prolog', regex: ';' },
  69. { include: '#basic_elem' } ],
  70. '#fact':
  71. [ { token:
  72. [ 'entity.name.function.fact.prolog',
  73. 'punctuation.begin.fact.parameters.prolog' ],
  74. regex: '([a-z]\\w*)(\\()(?!.*:-)',
  75. push:
  76. [ { token:
  77. [ 'punctuation.end.fact.parameters.prolog',
  78. 'punctuation.end.fact.prolog' ],
  79. regex: '(\\))(\\.?)',
  80. next: 'pop' },
  81. { include: '#parameter' },
  82. { defaultToken: 'meta.fact.prolog' } ] } ],
  83. '#list':
  84. [ { token: 'punctuation.begin.list.prolog',
  85. regex: '\\[(?=.*\\])',
  86. push:
  87. [ { token: 'punctuation.end.list.prolog',
  88. regex: '\\]',
  89. next: 'pop' },
  90. { include: '#comment' },
  91. { token: 'punctuation.separator.list.prolog', regex: ',' },
  92. { token: 'punctuation.concat.list.prolog',
  93. regex: '\\|',
  94. push:
  95. [ { token: 'meta.list.concat.prolog',
  96. regex: '(?=\\s*\\])',
  97. next: 'pop' },
  98. { include: '#basic_elem' },
  99. { defaultToken: 'meta.list.concat.prolog' } ] },
  100. { include: '#basic_elem' },
  101. { defaultToken: 'meta.list.prolog' } ] } ],
  102. '#operators':
  103. [ { token: 'keyword.operator.prolog',
  104. regex: '\\\\\\+|\\bnot\\b|\\bis\\b|->|[><]|[><\\\\:=]?=|(?:=\\\\|\\\\=)=' } ],
  105. '#parameter':
  106. [ { token: 'variable.language.anonymous.prolog',
  107. regex: '\\b_\\b' },
  108. { token: 'variable.parameter.prolog',
  109. regex: '\\b[A-Z_]\\w*\\b' },
  110. { token: 'punctuation.separator.parameters.prolog', regex: ',' },
  111. { include: '#basic_elem' },
  112. { token: 'text', regex: '[^\\s]' } ],
  113. '#rule':
  114. [ { token: 'meta.rule.prolog',
  115. regex: '(?=[a-z]\\w*.*:-)',
  116. push:
  117. [ { token: 'punctuation.rule.end.prolog',
  118. regex: '\\.',
  119. next: 'pop' },
  120. { token: 'meta.rule.signature.prolog',
  121. regex: '(?=[a-z]\\w*.*:-)',
  122. push:
  123. [ { token: 'meta.rule.signature.prolog',
  124. regex: '(?=:-)',
  125. next: 'pop' },
  126. { token: 'entity.name.function.rule.prolog',
  127. regex: '[a-z]\\w*(?=\\(|\\s*:-)' },
  128. { token: 'punctuation.rule.parameters.begin.prolog',
  129. regex: '\\(',
  130. push:
  131. [ { token: 'punctuation.rule.parameters.end.prolog',
  132. regex: '\\)',
  133. next: 'pop' },
  134. { include: '#parameter' },
  135. { defaultToken: 'meta.rule.parameters.prolog' } ] },
  136. { defaultToken: 'meta.rule.signature.prolog' } ] },
  137. { token: 'keyword.operator.definition.prolog',
  138. regex: ':-',
  139. push:
  140. [ { token: 'meta.rule.definition.prolog',
  141. regex: '(?=\\.)',
  142. next: 'pop' },
  143. { include: '#comment' },
  144. { include: '#expr' },
  145. { defaultToken: 'meta.rule.definition.prolog' } ] },
  146. { defaultToken: 'meta.rule.prolog' } ] } ],
  147. '#statement':
  148. [ { token: 'meta.statement.prolog',
  149. regex: '(?=[a-z]\\w*\\()',
  150. push:
  151. [ { token: 'punctuation.end.statement.parameters.prolog',
  152. regex: '\\)',
  153. next: 'pop' },
  154. { include: '#builtins' },
  155. { include: '#atom' },
  156. { token: 'punctuation.begin.statement.parameters.prolog',
  157. regex: '\\(',
  158. push:
  159. [ { token: 'meta.statement.parameters.prolog',
  160. regex: '(?=\\))',
  161. next: 'pop' },
  162. { token: 'punctuation.separator.statement.prolog', regex: ',' },
  163. { include: '#basic_elem' },
  164. { defaultToken: 'meta.statement.parameters.prolog' } ] },
  165. { defaultToken: 'meta.statement.prolog' } ] } ],
  166. '#string':
  167. [ { token: 'punctuation.definition.string.begin.prolog',
  168. regex: '\'',
  169. push:
  170. [ { token: 'punctuation.definition.string.end.prolog',
  171. regex: '\'',
  172. next: 'pop' },
  173. { token: 'constant.character.escape.prolog', regex: '\\\\.' },
  174. { token: 'constant.character.escape.quote.prolog',
  175. regex: '\'\'' },
  176. { defaultToken: 'string.quoted.single.prolog' } ] } ],
  177. '#variable':
  178. [ { token: 'variable.language.anonymous.prolog',
  179. regex: '\\b_\\b' },
  180. { token: 'variable.other.prolog',
  181. regex: '\\b[A-Z_][a-zA-Z0-9_]*\\b' } ] };
  182. this.normalizeRules();
  183. };
  184. PrologHighlightRules.metaData = { fileTypes: [ 'plg', 'prolog' ],
  185. foldingStartMarker: '(%\\s*region \\w*)|([a-z]\\w*.*:- ?)',
  186. foldingStopMarker: '(%\\s*end(\\s*region)?)|(?=\\.)',
  187. keyEquivalent: '^~P',
  188. name: 'Prolog',
  189. scopeName: 'source.prolog' };
  190. oop.inherits(PrologHighlightRules, TextHighlightRules);
  191. exports.PrologHighlightRules = PrologHighlightRules;
  192. });
  193. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  194. "use strict";
  195. var oop = ace_require("../../lib/oop");
  196. var Range = ace_require("../../range").Range;
  197. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  198. var FoldMode = exports.FoldMode = function(commentRegex) {
  199. if (commentRegex) {
  200. this.foldingStartMarker = new RegExp(
  201. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  202. );
  203. this.foldingStopMarker = new RegExp(
  204. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  205. );
  206. }
  207. };
  208. oop.inherits(FoldMode, BaseFoldMode);
  209. (function() {
  210. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  211. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  212. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  213. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  214. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  215. this._getFoldWidgetBase = this.getFoldWidget;
  216. this.getFoldWidget = function(session, foldStyle, row) {
  217. var line = session.getLine(row);
  218. if (this.singleLineBlockCommentRe.test(line)) {
  219. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  220. return "";
  221. }
  222. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  223. if (!fw && this.startRegionRe.test(line))
  224. return "start"; // lineCommentRegionStart
  225. return fw;
  226. };
  227. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  228. var line = session.getLine(row);
  229. if (this.startRegionRe.test(line))
  230. return this.getCommentRegionBlock(session, line, row);
  231. var match = line.match(this.foldingStartMarker);
  232. if (match) {
  233. var i = match.index;
  234. if (match[1])
  235. return this.openingBracketBlock(session, match[1], row, i);
  236. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  237. if (range && !range.isMultiLine()) {
  238. if (forceMultiline) {
  239. range = this.getSectionRange(session, row);
  240. } else if (foldStyle != "all")
  241. range = null;
  242. }
  243. return range;
  244. }
  245. if (foldStyle === "markbegin")
  246. return;
  247. var match = line.match(this.foldingStopMarker);
  248. if (match) {
  249. var i = match.index + match[0].length;
  250. if (match[1])
  251. return this.closingBracketBlock(session, match[1], row, i);
  252. return session.getCommentFoldRange(row, i, -1);
  253. }
  254. };
  255. this.getSectionRange = function(session, row) {
  256. var line = session.getLine(row);
  257. var startIndent = line.search(/\S/);
  258. var startRow = row;
  259. var startColumn = line.length;
  260. row = row + 1;
  261. var endRow = row;
  262. var maxRow = session.getLength();
  263. while (++row < maxRow) {
  264. line = session.getLine(row);
  265. var indent = line.search(/\S/);
  266. if (indent === -1)
  267. continue;
  268. if (startIndent > indent)
  269. break;
  270. var subRange = this.getFoldWidgetRange(session, "all", row);
  271. if (subRange) {
  272. if (subRange.start.row <= startRow) {
  273. break;
  274. } else if (subRange.isMultiLine()) {
  275. row = subRange.end.row;
  276. } else if (startIndent == indent) {
  277. break;
  278. }
  279. }
  280. endRow = row;
  281. }
  282. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  283. };
  284. this.getCommentRegionBlock = function(session, line, row) {
  285. var startColumn = line.search(/\s*$/);
  286. var maxRow = session.getLength();
  287. var startRow = row;
  288. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  289. var depth = 1;
  290. while (++row < maxRow) {
  291. line = session.getLine(row);
  292. var m = re.exec(line);
  293. if (!m) continue;
  294. if (m[1]) depth--;
  295. else depth++;
  296. if (!depth) break;
  297. }
  298. var endRow = row;
  299. if (endRow > startRow) {
  300. return new Range(startRow, startColumn, endRow, line.length);
  301. }
  302. };
  303. }).call(FoldMode.prototype);
  304. });
  305. define("ace/mode/prolog",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/prolog_highlight_rules","ace/mode/folding/cstyle"], function(ace_require, exports, module) {
  306. "use strict";
  307. var oop = ace_require("../lib/oop");
  308. var TextMode = ace_require("./text").Mode;
  309. var PrologHighlightRules = ace_require("./prolog_highlight_rules").PrologHighlightRules;
  310. var FoldMode = ace_require("./folding/cstyle").FoldMode;
  311. var Mode = function() {
  312. this.HighlightRules = PrologHighlightRules;
  313. this.foldingRules = new FoldMode();
  314. this.$behaviour = this.$defaultBehaviour;
  315. };
  316. oop.inherits(Mode, TextMode);
  317. (function() {
  318. this.lineCommentStart = "%";
  319. this.blockComment = {start: "/*", end: "*/"};
  320. this.$id = "ace/mode/prolog";
  321. }).call(Mode.prototype);
  322. exports.Mode = Mode;
  323. }); (function() {
  324. window.ace_require(["ace/mode/prolog"], function(m) {
  325. if (typeof module == "object" && typeof exports == "object" && module) {
  326. module.exports = m;
  327. }
  328. });
  329. })();