mode-lean.js 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ace.define("ace/mode/doc_comment_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 DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. }
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. ace.define("ace/mode/lean_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
  42. "use strict";
  43. var oop = require("../lib/oop");
  44. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  46. var leanHighlightRules = function() {
  47. var keywordControls = (
  48. [ "add_rewrite", "alias", "as", "assume", "attribute",
  49. "begin", "by", "calc", "calc_refl", "calc_subst", "calc_trans", "check",
  50. "classes", "coercions", "conjecture", "constants", "context",
  51. "corollary", "else", "end", "environment", "eval", "example",
  52. "exists", "exit", "export", "exposing", "extends", "fields", "find_decl",
  53. "forall", "from", "fun", "have", "help", "hiding", "if",
  54. "import", "in", "infix", "infixl", "infixr", "instances",
  55. "let", "local", "match", "namespace", "notation", "obtain", "obtains",
  56. "omit", "opaque", "open", "options", "parameter", "parameters", "postfix",
  57. "precedence", "prefix", "premise", "premises", "print", "private", "proof",
  58. "protected", "qed", "raw", "renaming", "section", "set_option",
  59. "show", "tactic_hint", "take", "then", "universe",
  60. "universes", "using", "variable", "variables", "with"].join("|")
  61. );
  62. var nameProviders = (
  63. ["inductive", "structure", "record", "theorem", "axiom",
  64. "axioms", "lemma", "hypothesis", "definition", "constant"].join("|")
  65. );
  66. var storageType = (
  67. ["Prop", "Type", "Type'", "Type₊", "Type₁", "Type₂", "Type₃"].join("|")
  68. );
  69. var storageModifiers = (
  70. "\\[(" +
  71. ["abbreviations", "all-transparent", "begin-end-hints", "class", "classes", "coercion",
  72. "coercions", "declarations", "decls", "instance", "irreducible",
  73. "multiple-instances", "notation", "notations", "parsing-only", "persistent",
  74. "reduce-hints", "reducible", "tactic-hints", "visible", "wf", "whnf"
  75. ].join("|") +
  76. ")\\]"
  77. );
  78. var keywordOperators = (
  79. [].join("|")
  80. );
  81. var keywordMapper = this.$keywords = this.createKeywordMapper({
  82. "keyword.control" : keywordControls,
  83. "storage.type" : storageType,
  84. "keyword.operator" : keywordOperators,
  85. "variable.language": "sorry"
  86. }, "identifier");
  87. var identifierRe = "[A-Za-z_\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2100-\u214f][A-Za-z0-9_'\u03b1-\u03ba\u03bc-\u03fb\u1f00-\u1ffe\u2070-\u2079\u207f-\u2089\u2090-\u209c\u2100-\u214f]*";
  88. var operatorRe = new RegExp(["#", "@", "->", "∼", "↔", "/", "==", "=", ":=", "<->",
  89. "/\\", "\\/", "∧", "∨", "≠", "<", ">", "≤", "≥", "¬",
  90. "<=", ">=", "⁻¹", "⬝", "▸", "\\+", "\\*", "-", "/",
  91. "λ", "→", "∃", "∀", ":="].join("|"));
  92. this.$rules = {
  93. "start" : [
  94. {
  95. token : "comment", // single line comment "--"
  96. regex : "--.*$"
  97. },
  98. DocCommentHighlightRules.getStartRule("doc-start"),
  99. {
  100. token : "comment", // multi line comment "/-"
  101. regex : "\\/-",
  102. next : "comment"
  103. }, {
  104. stateName: "qqstring",
  105. token : "string.start", regex : '"', next : [
  106. {token : "string.end", regex : '"', next : "start"},
  107. {token : "constant.language.escape", regex : /\\[n"\\]/},
  108. {defaultToken: "string"}
  109. ]
  110. }, {
  111. token : "keyword.control", regex : nameProviders, next : [
  112. {token : "variable.language", regex : identifierRe, next : "start"} ]
  113. }, {
  114. token : "constant.numeric", // hex
  115. regex : "0[xX][0-9a-fA-F]+(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  116. }, {
  117. token : "constant.numeric", // float
  118. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  119. }, {
  120. token : "storage.modifier",
  121. regex : storageModifiers
  122. }, {
  123. token : keywordMapper,
  124. regex : identifierRe
  125. }, {
  126. token : "operator",
  127. regex : operatorRe
  128. }, {
  129. token : "punctuation.operator",
  130. regex : "\\?|\\:|\\,|\\;|\\."
  131. }, {
  132. token : "paren.lparen",
  133. regex : "[[({]"
  134. }, {
  135. token : "paren.rparen",
  136. regex : "[\\])}]"
  137. }, {
  138. token : "text",
  139. regex : "\\s+"
  140. }
  141. ],
  142. "comment" : [ {token: "comment", regex: "-/", next: "start"},
  143. {defaultToken: "comment"} ]
  144. };
  145. this.embedRules(DocCommentHighlightRules, "doc-",
  146. [ DocCommentHighlightRules.getEndRule("start") ]);
  147. this.normalizeRules();
  148. };
  149. oop.inherits(leanHighlightRules, TextHighlightRules);
  150. exports.leanHighlightRules = leanHighlightRules;
  151. });
  152. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  153. "use strict";
  154. var Range = require("../range").Range;
  155. var MatchingBraceOutdent = function() {};
  156. (function() {
  157. this.checkOutdent = function(line, input) {
  158. if (! /^\s+$/.test(line))
  159. return false;
  160. return /^\s*\}/.test(input);
  161. };
  162. this.autoOutdent = function(doc, row) {
  163. var line = doc.getLine(row);
  164. var match = line.match(/^(\s*\})/);
  165. if (!match) return 0;
  166. var column = match[1].length;
  167. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  168. if (!openBracePos || openBracePos.row == row) return 0;
  169. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  170. doc.replace(new Range(row, 0, row, column-1), indent);
  171. };
  172. this.$getIndent = function(line) {
  173. return line.match(/^\s*/)[0];
  174. };
  175. }).call(MatchingBraceOutdent.prototype);
  176. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  177. });
  178. ace.define("ace/mode/lean",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/lean_highlight_rules","ace/mode/matching_brace_outdent","ace/range"], function(require, exports, module) {
  179. "use strict";
  180. var oop = require("../lib/oop");
  181. var TextMode = require("./text").Mode;
  182. var leanHighlightRules = require("./lean_highlight_rules").leanHighlightRules;
  183. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  184. var Range = require("../range").Range;
  185. var Mode = function() {
  186. this.HighlightRules = leanHighlightRules;
  187. this.$outdent = new MatchingBraceOutdent();
  188. };
  189. oop.inherits(Mode, TextMode);
  190. (function() {
  191. this.lineCommentStart = "--";
  192. this.blockComment = {start: "/-", end: "-/"};
  193. this.getNextLineIndent = function(state, line, tab) {
  194. var indent = this.$getIndent(line);
  195. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  196. var tokens = tokenizedLine.tokens;
  197. var endState = tokenizedLine.state;
  198. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  199. return indent;
  200. }
  201. if (state == "start") {
  202. var match = line.match(/^.*[\{\(\[]\s*$/);
  203. if (match) {
  204. indent += tab;
  205. }
  206. } else if (state == "doc-start") {
  207. if (endState == "start") {
  208. return "";
  209. }
  210. var match = line.match(/^\s*(\/?)\*/);
  211. if (match) {
  212. if (match[1]) {
  213. indent += " ";
  214. }
  215. indent += "- ";
  216. }
  217. }
  218. return indent;
  219. };
  220. this.checkOutdent = function(state, line, input) {
  221. return this.$outdent.checkOutdent(line, input);
  222. };
  223. this.autoOutdent = function(state, doc, row) {
  224. this.$outdent.autoOutdent(doc, row);
  225. };
  226. this.$id = "ace/mode/lean";
  227. }).call(Mode.prototype);
  228. exports.Mode = Mode;
  229. });