mode-logtalk.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. ace.define("ace/mode/logtalk_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 LogtalkHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { token: 'punctuation.definition.comment.logtalk',
  8. regex: '/\\*',
  9. push:
  10. [ { token: 'punctuation.definition.comment.logtalk',
  11. regex: '\\*/',
  12. next: 'pop' },
  13. { defaultToken: 'comment.block.logtalk' } ] },
  14. { todo: 'fix grouping',
  15. token:
  16. [ 'comment.line.percentage.logtalk',
  17. 'punctuation.definition.comment.logtalk' ],
  18. regex: '%.*$\\n?' },
  19. { todo: 'fix grouping',
  20. token:
  21. [ 'storage.type.opening.logtalk',
  22. 'punctuation.definition.storage.type.logtalk' ],
  23. regex: ':-\\s(?:object|protocol|category|module)(?=[(])' },
  24. { todo: 'fix grouping',
  25. token:
  26. [ 'storage.type.closing.logtalk',
  27. 'punctuation.definition.storage.type.logtalk' ],
  28. regex: ':-\\send_(?:object|protocol|category)(?=[.])' },
  29. { caseInsensitive: false,
  30. token: 'storage.type.relations.logtalk',
  31. regex: '\\b(?:complements|extends|i(?:nstantiates|mp(?:orts|lements))|specializes)(?=[(])' },
  32. { caseInsensitive: false,
  33. todo: 'fix grouping',
  34. token:
  35. [ 'storage.modifier.others.logtalk',
  36. 'punctuation.definition.storage.modifier.logtalk' ],
  37. regex: ':-\\s(?:e(?:lse|ndif)|built_in|dynamic|synchronized|threaded)(?=[.])' },
  38. { caseInsensitive: false,
  39. todo: 'fix grouping',
  40. token:
  41. [ 'storage.modifier.others.logtalk',
  42. 'punctuation.definition.storage.modifier.logtalk' ],
  43. regex: ':-\\s(?:c(?:alls|oinductive)|e(?:lif|n(?:coding|sure_loaded)|xport)|i(?:f|n(?:clude|itialization|fo))|reexport|set_(?:logtalk|prolog)_flag|uses)(?=[(])' },
  44. { caseInsensitive: false,
  45. todo: 'fix grouping',
  46. token:
  47. [ 'storage.modifier.others.logtalk',
  48. 'punctuation.definition.storage.modifier.logtalk' ],
  49. regex: ':-\\s(?:alias|info|d(?:ynamic|iscontiguous)|m(?:eta_(?:non_terminal|predicate)|ode|ultifile)|p(?:ublic|r(?:otected|ivate))|op|use(?:s|_module)|synchronized)(?=[(])' },
  50. { token: 'keyword.operator.message-sending.logtalk',
  51. regex: '(:|::|\\^\\^)' },
  52. { token: 'keyword.operator.external-call.logtalk',
  53. regex: '([{}])' },
  54. { token: 'keyword.operator.mode.logtalk', regex: '(\\?|@)' },
  55. { token: 'keyword.operator.comparison.term.logtalk',
  56. regex: '(@=<|@<|@>|@>=|==|\\\\==)' },
  57. { token: 'keyword.operator.comparison.arithmetic.logtalk',
  58. regex: '(=<|<|>|>=|=:=|=\\\\=)' },
  59. { token: 'keyword.operator.bitwise.logtalk',
  60. regex: '(<<|>>|/\\\\|\\\\/|\\\\)' },
  61. { token: 'keyword.operator.evaluable.logtalk',
  62. regex: '\\b(?:e|pi|div|mod|rem)\\b(?![-!(^~])' },
  63. { token: 'keyword.operator.evaluable.logtalk',
  64. regex: '(\\*\\*|\\+|-|\\*|/|//)' },
  65. { token: 'keyword.operator.misc.logtalk',
  66. regex: '(:-|!|\\\\+|,|;|-->|->|=|\\=|\\.|=\\.\\.|\\^|\\bas\\b|\\bis\\b)' },
  67. { caseInsensitive: false,
  68. token: 'support.function.evaluable.logtalk',
  69. regex: '\\b(a(bs|cos|sin|tan|tan2)|c(eiling|os)|div|exp|flo(at(_(integer|fractional)_part)?|or)|log|m(ax|in|od)|r(em|ound)|s(i(n|gn)|qrt)|t(an|runcate)|xor)(?=[(])' },
  70. { token: 'support.function.control.logtalk',
  71. regex: '\\b(?:true|fa(?:il|lse)|repeat|(?:instantiation|system)_error)\\b(?![-!(^~])' },
  72. { token: 'support.function.control.logtalk',
  73. regex: '\\b((?:type|domain|existence|permission|representation|evaluation|resource|syntax)_error)(?=[(])' },
  74. { token: 'support.function.control.logtalk',
  75. regex: '\\b(?:ca(?:ll|tch)|ignore|throw|once)(?=[(])' },
  76. { token: 'support.function.chars-and-bytes-io.logtalk',
  77. regex: '\\b(?:(?:get|p(?:eek|ut))_(c(?:har|ode)|byte)|nl)(?=[(])' },
  78. { token: 'support.function.chars-and-bytes-io.logtalk',
  79. regex: '\\bnl\\b' },
  80. { token: 'support.function.atom-term-processing.logtalk',
  81. regex: '\\b(?:atom_(?:length|c(?:hars|o(?:ncat|des)))|sub_atom|char_code|number_c(?:har|ode)s)(?=[(])' },
  82. { caseInsensitive: false,
  83. token: 'support.function.term-testing.logtalk',
  84. regex: '\\b(?:var|atom(ic)?|integer|float|c(?:allable|ompound)|n(?:onvar|umber)|ground|acyclic_term)(?=[(])' },
  85. { token: 'support.function.term-comparison.logtalk',
  86. regex: '\\b(compare)(?=[(])' },
  87. { token: 'support.function.term-io.logtalk',
  88. regex: '\\b(?:read(_term)?|write(?:q|_(?:canonical|term))?|(current_)?(?:char_conversion|op))(?=[(])' },
  89. { caseInsensitive: false,
  90. token: 'support.function.term-creation-and-decomposition.logtalk',
  91. regex: '\\b(arg|copy_term|functor|numbervars|term_variables)(?=[(])' },
  92. { caseInsensitive: false,
  93. token: 'support.function.term-unification.logtalk',
  94. regex: '\\b(subsumes_term|unify_with_occurs_check)(?=[(])' },
  95. { caseInsensitive: false,
  96. token: 'support.function.stream-selection-and-control.logtalk',
  97. regex: '\\b(?:(?:se|curren)t_(?:in|out)put|open|close|flush_output|stream_property|at_end_of_stream|set_stream_position)(?=[(])' },
  98. { token: 'support.function.stream-selection-and-control.logtalk',
  99. regex: '\\b(?:flush_output|at_end_of_stream)\\b' },
  100. { token: 'support.function.prolog-flags.logtalk',
  101. regex: '\\b((?:se|curren)t_prolog_flag)(?=[(])' },
  102. { token: 'support.function.compiling-and-loading.logtalk',
  103. regex: '\\b(logtalk_(?:compile|l(?:ibrary_path|oad|oad_context)|make(_target_action)?))(?=[(])' },
  104. { token: 'support.function.compiling-and-loading.logtalk',
  105. regex: '\\b(logtalk_make)\\b' },
  106. { caseInsensitive: false,
  107. token: 'support.function.event-handling.logtalk',
  108. regex: '\\b(?:(?:abolish|define)_events|current_event)(?=[(])' },
  109. { token: 'support.function.implementation-defined-hooks.logtalk',
  110. regex: '\\b(?:(?:create|current|set)_logtalk_flag|halt)(?=[(])' },
  111. { token: 'support.function.implementation-defined-hooks.logtalk',
  112. regex: '\\b(halt)\\b' },
  113. { token: 'support.function.sorting.logtalk',
  114. regex: '\\b((key)?(sort))(?=[(])' },
  115. { caseInsensitive: false,
  116. token: 'support.function.entity-creation-and-abolishing.logtalk',
  117. regex: '\\b((c(?:reate|urrent)|abolish)_(?:object|protocol|category))(?=[(])' },
  118. { caseInsensitive: false,
  119. token: 'support.function.reflection.logtalk',
  120. regex: '\\b((object|protocol|category)_property|co(mplements_object|nforms_to_protocol)|extends_(object|protocol|category)|imp(orts_category|lements_protocol)|(instantiat|specializ)es_class)(?=[(])' },
  121. { token: 'support.function.logtalk',
  122. regex: '\\b((?:for|retract)all)(?=[(])' },
  123. { caseInsensitive: false,
  124. token: 'support.function.execution-context.logtalk',
  125. regex: '\\b(?:context|parameter|se(?:lf|nder)|this)(?=[(])' },
  126. { token: 'support.function.database.logtalk',
  127. regex: '\\b(?:a(?:bolish|ssert(?:a|z))|clause|retract(all)?)(?=[(])' },
  128. { token: 'support.function.all-solutions.logtalk',
  129. regex: '\\b((?:bag|set)of|f(?:ind|or)all)(?=[(])' },
  130. { caseInsensitive: false,
  131. token: 'support.function.multi-threading.logtalk',
  132. regex: '\\b(threaded(_(call|once|ignore|exit|peek|wait|notify))?)(?=[(])' },
  133. { caseInsensitive: false,
  134. token: 'support.function.engines.logtalk',
  135. regex: '\\b(threaded_engine(_(create|destroy|self|next(?:_reified)?|yield|post|fetch))?)(?=[(])' },
  136. { caseInsensitive: false,
  137. token: 'support.function.reflection.logtalk',
  138. regex: '\\b(?:current_predicate|predicate_property)(?=[(])' },
  139. { token: 'support.function.event-handler.logtalk',
  140. regex: '\\b(?:before|after)(?=[(])' },
  141. { token: 'support.function.message-forwarding-handler.logtalk',
  142. regex: '\\b(forward)(?=[(])' },
  143. { token: 'support.function.grammar-rule.logtalk',
  144. regex: '\\b(?:expand_(?:goal|term)|(?:goal|term)_expansion|phrase)(?=[(])' },
  145. { token: 'punctuation.definition.string.begin.logtalk',
  146. regex: '\'',
  147. push:
  148. [ { token: 'constant.character.escape.logtalk',
  149. regex: '\\\\([\\\\abfnrtv"\']|(x[a-fA-F0-9]+|[0-7]+)\\\\)' },
  150. { token: 'punctuation.definition.string.end.logtalk',
  151. regex: '\'',
  152. next: 'pop' },
  153. { defaultToken: 'string.quoted.single.logtalk' } ] },
  154. { token: 'punctuation.definition.string.begin.logtalk',
  155. regex: '"',
  156. push:
  157. [ { token: 'constant.character.escape.logtalk', regex: '\\\\.' },
  158. { token: 'punctuation.definition.string.end.logtalk',
  159. regex: '"',
  160. next: 'pop' },
  161. { defaultToken: 'string.quoted.double.logtalk' } ] },
  162. { token: 'constant.numeric.logtalk',
  163. regex: '\\b(0b[0-1]+|0o[0-7]+|0x[0-9a-fA-F]+)\\b' },
  164. { token: 'constant.numeric.logtalk',
  165. regex: '\\b(0\'\\\\.|0\'.|0\'\'|0\'")' },
  166. { token: 'constant.numeric.logtalk',
  167. regex: '\\b(\\d+\\.?\\d*((e|E)(\\+|-)?\\d+)?)\\b' },
  168. { token: 'variable.other.logtalk',
  169. regex: '\\b([A-Z_][A-Za-z0-9_]*)\\b' } ] };
  170. this.normalizeRules();
  171. };
  172. oop.inherits(LogtalkHighlightRules, TextHighlightRules);
  173. exports.LogtalkHighlightRules = LogtalkHighlightRules;
  174. });
  175. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  176. "use strict";
  177. var oop = require("../../lib/oop");
  178. var Range = require("../../range").Range;
  179. var BaseFoldMode = require("./fold_mode").FoldMode;
  180. var FoldMode = exports.FoldMode = function(commentRegex) {
  181. if (commentRegex) {
  182. this.foldingStartMarker = new RegExp(
  183. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  184. );
  185. this.foldingStopMarker = new RegExp(
  186. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  187. );
  188. }
  189. };
  190. oop.inherits(FoldMode, BaseFoldMode);
  191. (function() {
  192. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  193. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  194. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  195. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  196. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  197. this._getFoldWidgetBase = this.getFoldWidget;
  198. this.getFoldWidget = function(session, foldStyle, row) {
  199. var line = session.getLine(row);
  200. if (this.singleLineBlockCommentRe.test(line)) {
  201. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  202. return "";
  203. }
  204. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  205. if (!fw && this.startRegionRe.test(line))
  206. return "start"; // lineCommentRegionStart
  207. return fw;
  208. };
  209. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  210. var line = session.getLine(row);
  211. if (this.startRegionRe.test(line))
  212. return this.getCommentRegionBlock(session, line, row);
  213. var match = line.match(this.foldingStartMarker);
  214. if (match) {
  215. var i = match.index;
  216. if (match[1])
  217. return this.openingBracketBlock(session, match[1], row, i);
  218. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  219. if (range && !range.isMultiLine()) {
  220. if (forceMultiline) {
  221. range = this.getSectionRange(session, row);
  222. } else if (foldStyle != "all")
  223. range = null;
  224. }
  225. return range;
  226. }
  227. if (foldStyle === "markbegin")
  228. return;
  229. var match = line.match(this.foldingStopMarker);
  230. if (match) {
  231. var i = match.index + match[0].length;
  232. if (match[1])
  233. return this.closingBracketBlock(session, match[1], row, i);
  234. return session.getCommentFoldRange(row, i, -1);
  235. }
  236. };
  237. this.getSectionRange = function(session, row) {
  238. var line = session.getLine(row);
  239. var startIndent = line.search(/\S/);
  240. var startRow = row;
  241. var startColumn = line.length;
  242. row = row + 1;
  243. var endRow = row;
  244. var maxRow = session.getLength();
  245. while (++row < maxRow) {
  246. line = session.getLine(row);
  247. var indent = line.search(/\S/);
  248. if (indent === -1)
  249. continue;
  250. if (startIndent > indent)
  251. break;
  252. var subRange = this.getFoldWidgetRange(session, "all", row);
  253. if (subRange) {
  254. if (subRange.start.row <= startRow) {
  255. break;
  256. } else if (subRange.isMultiLine()) {
  257. row = subRange.end.row;
  258. } else if (startIndent == indent) {
  259. break;
  260. }
  261. }
  262. endRow = row;
  263. }
  264. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  265. };
  266. this.getCommentRegionBlock = function(session, line, row) {
  267. var startColumn = line.search(/\s*$/);
  268. var maxRow = session.getLength();
  269. var startRow = row;
  270. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  271. var depth = 1;
  272. while (++row < maxRow) {
  273. line = session.getLine(row);
  274. var m = re.exec(line);
  275. if (!m) continue;
  276. if (m[1]) depth--;
  277. else depth++;
  278. if (!depth) break;
  279. }
  280. var endRow = row;
  281. if (endRow > startRow) {
  282. return new Range(startRow, startColumn, endRow, line.length);
  283. }
  284. };
  285. }).call(FoldMode.prototype);
  286. });
  287. ace.define("ace/mode/logtalk",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/logtalk_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  288. "use strict";
  289. var oop = require("../lib/oop");
  290. var TextMode = require("./text").Mode;
  291. var Tokenizer = require("../tokenizer").Tokenizer;
  292. var LogtalkHighlightRules = require("./logtalk_highlight_rules").LogtalkHighlightRules;
  293. var FoldMode = require("./folding/cstyle").FoldMode;
  294. var Mode = function() {
  295. this.HighlightRules = LogtalkHighlightRules;
  296. this.foldingRules = new FoldMode();
  297. this.$behaviour = this.$defaultBehaviour;
  298. };
  299. oop.inherits(Mode, TextMode);
  300. (function() {
  301. this.lineCommentStart = "%";
  302. this.blockComment = {start: "/*", end: "*/"};
  303. this.$id = "ace/mode/logtalk";
  304. }).call(Mode.prototype);
  305. exports.Mode = Mode;
  306. }); (function() {
  307. ace.require(["ace/mode/logtalk"], function(m) {
  308. if (typeof module == "object" && typeof exports == "object" && module) {
  309. module.exports = m;
  310. }
  311. });
  312. })();