bb7afd142656785e03deb43ec5d49526.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. ace.define("ace/mode/prql_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){// https://prql-lang.org/
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var PrqlHighlightRules = function () {
  6. var builtinFunctions = "min|max|sum|average|stddev|every|any|concat_array|count|" +
  7. "lag|lead|first|last|rank|rank_dense|row_number|" +
  8. "round|as|in|" +
  9. "tuple_every|tuple_map|tuple_zip|_eq|_is_null|" +
  10. "from_text|" +
  11. "lower|upper|" +
  12. "read_parquet|read_csv";
  13. var builtinTypes = [
  14. "bool",
  15. "int",
  16. "int8",
  17. "int16",
  18. "int32",
  19. "int64",
  20. "int128",
  21. "float",
  22. "text",
  23. "timestamp",
  24. "set"
  25. ].join("|");
  26. var keywordMapper = this.createKeywordMapper({
  27. "constant.language": "null",
  28. "constant.language.boolean": "true|false",
  29. "keyword": "let|into|case|prql|type|module|internal",
  30. "storage.type": "let|func",
  31. "support.function": builtinFunctions,
  32. "support.type": builtinTypes,
  33. "variable.language": "date|math"
  34. }, "identifier");
  35. var escapeRe = /\\(\d+|['"\\&bfnrt]|u\{[0-9a-fA-F]{1,6}\}|x[0-9a-fA-F]{2})/;
  36. var identifierRe = /[A-Za-z_][a-z_A-Z0-9]/.source;
  37. var numRe = /(?:\d\d*(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+\b)?/.source;
  38. var bidi = "[\\u202A\\u202B\\u202D\\u202E\\u2066\\u2067\\u2068\\u202C\\u2069]";
  39. this.$rules = {
  40. start: [
  41. {
  42. token: "string.start",
  43. regex: 's?"',
  44. next: "string"
  45. }, {
  46. token: "string.start",
  47. regex: 'f"',
  48. next: "fstring"
  49. }, {
  50. token: "string.start",
  51. regex: 'r"',
  52. next: "rstring"
  53. }, {
  54. token: "string.single",
  55. start: "'",
  56. end: "'"
  57. }, {
  58. token: "string.character",
  59. regex: "'(?:" + escapeRe.source + "|.)'?"
  60. }, {
  61. token: "constant.language",
  62. regex: "^" + identifierRe + "*"
  63. }, {
  64. token: ["constant.numeric", "keyword"],
  65. regex: "(" + numRe + ")(years|months|weeks|days|hours|minutes|seconds|milliseconds|microseconds)"
  66. }, {
  67. token: "constant.numeric", // hexadecimal, octal and binary
  68. regex: /0(?:[xX][0-9a-fA-F]+|[oO][0-7]+|[bB][01]+)\b/
  69. }, {
  70. token: "constant.numeric", // decimal integers and floats
  71. regex: numRe
  72. }, {
  73. token: "comment.block.documentation",
  74. regex: "#!.*"
  75. }, {
  76. token: "comment.line.number-sign",
  77. regex: "#.*"
  78. }, {
  79. token: "keyword.operator",
  80. regex: /\|\s*/,
  81. next: "pipe"
  82. }, {
  83. token: "keyword.operator",
  84. regex: /->|=>|==|!=|>=|<=|~=|&&|\|\||\?\?|\/\/|@/
  85. }, {
  86. token: "invalid.illegal",
  87. regex: bidi
  88. }, {
  89. token: "punctuation.operator",
  90. regex: /[,`]/
  91. }, {
  92. token: keywordMapper,
  93. regex: "[\\w\\xff-\\u218e\\u2455-\\uffff]+\\b"
  94. }, {
  95. token: "paren.lparen",
  96. regex: /[\[({]/
  97. }, {
  98. token: "paren.rparen",
  99. regex: /[\])}]/
  100. }
  101. ],
  102. pipe: [{
  103. token: "constant.language",
  104. regex: identifierRe + "*",
  105. next: "pop"
  106. }, {
  107. token: "error",
  108. regex: "",
  109. next: "pop"
  110. }],
  111. string: [{
  112. token: "constant.character.escape",
  113. regex: escapeRe
  114. }, {
  115. token: "text",
  116. regex: /\\(\s|$)/,
  117. next: "stringGap"
  118. }, {
  119. token: "string.end",
  120. regex: '"',
  121. next: "start"
  122. }, {
  123. token: "invalid.illegal",
  124. regex: bidi
  125. }, {
  126. defaultToken: "string.double"
  127. }],
  128. stringGap: [{
  129. token: "text",
  130. regex: /\\/,
  131. next: "string"
  132. }, {
  133. token: "error",
  134. regex: "",
  135. next: "start"
  136. }],
  137. fstring: [{
  138. token: "constant.character.escape",
  139. regex: escapeRe
  140. }, {
  141. token: "string.end",
  142. regex: '"',
  143. next: "start"
  144. }, {
  145. token: "invalid.illegal",
  146. regex: bidi
  147. }, {
  148. token: "paren.lparen",
  149. regex: "{",
  150. push: "fstringParenRules"
  151. }, {
  152. token: "invalid.illegal",
  153. regex: bidi
  154. }, {
  155. defaultToken: "string"
  156. }],
  157. fstringParenRules: [{
  158. token: "constant.language",
  159. regex: "^" + identifierRe + "*"
  160. }, {
  161. token: "paren.rparen",
  162. regex: "}",
  163. next: "pop"
  164. }],
  165. rstring: [{
  166. token: "string.end",
  167. regex: '"',
  168. next: "start"
  169. }, {
  170. token: "invalid.illegal",
  171. regex: bidi
  172. }, {
  173. defaultToken: "string"
  174. }]
  175. };
  176. this.normalizeRules();
  177. };
  178. oop.inherits(PrqlHighlightRules, TextHighlightRules);
  179. exports.PrqlHighlightRules = PrqlHighlightRules;
  180. });
  181. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  182. var oop = require("../../lib/oop");
  183. var Range = require("../../range").Range;
  184. var BaseFoldMode = require("./fold_mode").FoldMode;
  185. var FoldMode = exports.FoldMode = function (commentRegex) {
  186. if (commentRegex) {
  187. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  188. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  189. }
  190. };
  191. oop.inherits(FoldMode, BaseFoldMode);
  192. (function () {
  193. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  194. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  195. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  196. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  197. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  198. this._getFoldWidgetBase = this.getFoldWidget;
  199. this.getFoldWidget = function (session, foldStyle, row) {
  200. var line = session.getLine(row);
  201. if (this.singleLineBlockCommentRe.test(line)) {
  202. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  203. return "";
  204. }
  205. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  206. if (!fw && this.startRegionRe.test(line))
  207. return "start"; // lineCommentRegionStart
  208. return fw;
  209. };
  210. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  211. var line = session.getLine(row);
  212. if (this.startRegionRe.test(line))
  213. return this.getCommentRegionBlock(session, line, row);
  214. var match = line.match(this.foldingStartMarker);
  215. if (match) {
  216. var i = match.index;
  217. if (match[1])
  218. return this.openingBracketBlock(session, match[1], row, i);
  219. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  220. if (range && !range.isMultiLine()) {
  221. if (forceMultiline) {
  222. range = this.getSectionRange(session, row);
  223. }
  224. else if (foldStyle != "all")
  225. range = null;
  226. }
  227. return range;
  228. }
  229. if (foldStyle === "markbegin")
  230. return;
  231. var match = line.match(this.foldingStopMarker);
  232. if (match) {
  233. var i = match.index + match[0].length;
  234. if (match[1])
  235. return this.closingBracketBlock(session, match[1], row, i);
  236. return session.getCommentFoldRange(row, i, -1);
  237. }
  238. };
  239. this.getSectionRange = function (session, row) {
  240. var line = session.getLine(row);
  241. var startIndent = line.search(/\S/);
  242. var startRow = row;
  243. var startColumn = line.length;
  244. row = row + 1;
  245. var endRow = row;
  246. var maxRow = session.getLength();
  247. while (++row < maxRow) {
  248. line = session.getLine(row);
  249. var indent = line.search(/\S/);
  250. if (indent === -1)
  251. continue;
  252. if (startIndent > indent)
  253. break;
  254. var subRange = this.getFoldWidgetRange(session, "all", row);
  255. if (subRange) {
  256. if (subRange.start.row <= startRow) {
  257. break;
  258. }
  259. else if (subRange.isMultiLine()) {
  260. row = subRange.end.row;
  261. }
  262. else if (startIndent == indent) {
  263. break;
  264. }
  265. }
  266. endRow = row;
  267. }
  268. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  269. };
  270. this.getCommentRegionBlock = function (session, line, row) {
  271. var startColumn = line.search(/\s*$/);
  272. var maxRow = session.getLength();
  273. var startRow = row;
  274. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  275. var depth = 1;
  276. while (++row < maxRow) {
  277. line = session.getLine(row);
  278. var m = re.exec(line);
  279. if (!m)
  280. continue;
  281. if (m[1])
  282. depth--;
  283. else
  284. depth++;
  285. if (!depth)
  286. break;
  287. }
  288. var endRow = row;
  289. if (endRow > startRow) {
  290. return new Range(startRow, startColumn, endRow, line.length);
  291. }
  292. };
  293. }).call(FoldMode.prototype);
  294. });
  295. ace.define("ace/mode/prql",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/prql_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module){"use strict";
  296. var oop = require("../lib/oop");
  297. var TextMode = require("./text").Mode;
  298. var HighlightRules = require("./prql_highlight_rules").PrqlHighlightRules;
  299. var FoldMode = require("./folding/cstyle").FoldMode;
  300. var Mode = function () {
  301. this.HighlightRules = HighlightRules;
  302. this.foldingRules = new FoldMode();
  303. this.$behaviour = this.$defaultBehaviour;
  304. };
  305. oop.inherits(Mode, TextMode);
  306. (function () {
  307. this.lineCommentStart = "#";
  308. this.$id = "ace/mode/prql";
  309. }).call(Mode.prototype);
  310. exports.Mode = Mode;
  311. }); (function() {
  312. ace.require(["ace/mode/prql"], function(m) {
  313. if (typeof module == "object" && typeof exports == "object" && module) {
  314. module.exports = m;
  315. }
  316. });
  317. })();