PageRenderTime 34ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/Scripts/bower_components/ace-builds/src-noconflict/mode-prolog.js

https://gitlab.com/Ontology/OntologyWebModules
JavaScript | 364 lines | 323 code | 41 blank | 0 comment | 34 complexity | 3ca2a2975b821c3f2027cfcbee2c1e58 MD5 | raw file
  1. ace.define("ace/mode/prolog_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = 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. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  194. "use strict";
  195. var oop = require("../../lib/oop");
  196. var Range = require("../../range").Range;
  197. var BaseFoldMode = 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. ace.define("ace/mode/prolog",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/prolog_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  306. "use strict";
  307. var oop = require("../lib/oop");
  308. var TextMode = require("./text").Mode;
  309. var PrologHighlightRules = require("./prolog_highlight_rules").PrologHighlightRules;
  310. var FoldMode = 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. });