e100a40535c8ae342c0ad33bcd5d64a9.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. ace.define("ace/mode/zig_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var ZigHighlightRules = function () {
  5. this.$rules = {
  6. start: [{
  7. include: "#dummy_main"
  8. }],
  9. "#block": [{
  10. token: [
  11. "storage.type.zig",
  12. "text",
  13. "punctuation.section.braces.begin.zig"
  14. ],
  15. regex: /((?:[a-zA-Z_][\w.]*|@\".+\")?)(\s*)(\{)/,
  16. push: [{
  17. token: "punctuation.section.braces.end.zig",
  18. regex: /\}/,
  19. next: "pop"
  20. }, {
  21. include: "#dummy_main"
  22. }]
  23. }],
  24. "#character_escapes": [{
  25. token: "constant.character.escape.newline.zig",
  26. regex: /\\n/
  27. }, {
  28. token: "constant.character.escape.carrigereturn.zig",
  29. regex: /\\r/
  30. }, {
  31. token: "constant.character.escape.tabulator.zig",
  32. regex: /\\t/
  33. }, {
  34. token: "constant.character.escape.backslash.zig",
  35. regex: /\\\\/
  36. }, {
  37. token: "constant.character.escape.single-quote.zig",
  38. regex: /\\'/
  39. }, {
  40. token: "constant.character.escape.double-quote.zig",
  41. regex: /\\\"/
  42. }, {
  43. token: "constant.character.escape.hexidecimal.zig",
  44. regex: /\\x[a-fA-F\d]{2}/
  45. }, {
  46. token: "constant.character.escape.hexidecimal.zig",
  47. regex: /\\u\{[a-fA-F\d]{1,6}\}/
  48. }],
  49. "#comments": [{
  50. token: "comment.line.documentation.zig",
  51. regex: /\/\/[!\/](?=[^\/])/,
  52. push: [{
  53. token: "comment.line.documentation.zig",
  54. regex: /$/,
  55. next: "pop"
  56. }, {
  57. include: "#commentContents"
  58. }, {
  59. defaultToken: "comment.line.documentation.zig"
  60. }]
  61. }, {
  62. token: "comment.line.double-slash.zig",
  63. regex: /\/\//,
  64. push: [{
  65. token: "comment.line.double-slash.zig",
  66. regex: /$/,
  67. next: "pop"
  68. }, {
  69. include: "#commentContents"
  70. }, {
  71. defaultToken: "comment.line.double-slash.zig"
  72. }]
  73. }],
  74. "#commentContents": [{
  75. token: "keyword.todo.zig",
  76. regex: /\b(?:TODO|FIXME|XXX|NOTE)\b:?/
  77. }],
  78. "#constants": [{
  79. token: "constant.language.zig",
  80. regex: /\b(?:null|undefined|true|false)\b/
  81. }, {
  82. token: "constant.numeric.integer.zig",
  83. regex: /\b(?!\.)-?[\d_]+(?!\.)\b/
  84. }, {
  85. token: "constant.numeric.integer.hexadecimal.zig",
  86. regex: /\b(?!\.)0x[a-fA-F\d_]+(?!\.)\b/
  87. }, {
  88. token: "constant.numeric.integer.octal.zig",
  89. regex: /\b(?!\.)0o[0-7_]+(?!\.)\b/
  90. }, {
  91. token: "constant.numeric.integer.binary.zig",
  92. regex: /\b(?!\.)0b[01_]+(?!\.)\b/
  93. }, {
  94. token: "constant.numeric.float.zig",
  95. regex: /(?!\.)-?\b[\d_]+(?:\.[\d_]+)?(?:[eE][+-]?[\d_]+)?(?!\.)\b/
  96. }, {
  97. token: "constant.numeric.float.hexadecimal.zig",
  98. regex: /(?!\.)-?\b0x[a-fA-F\d_]+(?:\.[a-fA-F\d_]+)?[pP]?(?:[+-]?[\d_]+)?(?!\.)\b/
  99. }],
  100. "#container_decl": [{
  101. token: "entity.name.union.zig",
  102. regex: /\b(?!\d)(?:[a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*(?:extern|packed)?\b\s*union\s*[(\{])/
  103. }, {
  104. token: "entity.name.struct.zig",
  105. regex: /\b(?!\d)(?:[a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*(?:extern|packed)?\b\s*struct\s*[(\{])/
  106. }, {
  107. token: "entity.name.enum.zig",
  108. regex: /\b(?!\d)(?:[a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*(?:extern|packed)?\b\s*enum\s*[(\{])/
  109. }, {
  110. token: "entity.name.error.zig",
  111. regex: /\b(?!\d)(?:[a-zA-Z_]\w*|@\".+\")?(?=\s*=\s*error\s*[(\{])/
  112. }, {
  113. token: [
  114. "storage.type.error.zig",
  115. "punctuation.accessor.zig",
  116. "entity.name.error.zig"
  117. ],
  118. regex: /\b(error)(\.)([a-zA-Z_]\w*|@\".+\")/
  119. }],
  120. "#dummy_main": [{
  121. include: "#label"
  122. }, {
  123. include: "#function_type"
  124. }, {
  125. include: "#function_def"
  126. }, {
  127. include: "#punctuation"
  128. }, {
  129. include: "#storage_modifier"
  130. }, {
  131. include: "#container_decl"
  132. }, {
  133. include: "#constants"
  134. }, {
  135. include: "#comments"
  136. }, {
  137. include: "#strings"
  138. }, {
  139. include: "#storage"
  140. }, {
  141. include: "#keywords"
  142. }, {
  143. include: "#operators"
  144. }, {
  145. include: "#support"
  146. }, {
  147. include: "#field_decl"
  148. }, {
  149. include: "#block"
  150. }, {
  151. include: "#function_call"
  152. }, {
  153. include: "#enum_literal"
  154. }, {
  155. include: "#variables"
  156. }],
  157. "#enum_literal": [{
  158. token: "constant.language.enum",
  159. regex: /(?!\w|\)|\?|\}|\]|\*|\.)\.(?:[a-zA-Z_]\w*\b|@\"[^\"]*\")(?!\(|\s*=[^=>])/
  160. }],
  161. "#field_decl": [{
  162. token: [
  163. "variable.other.member.zig",
  164. "text",
  165. "punctuation.separator.zig",
  166. "text"
  167. ],
  168. regex: /([a-zA-Z_]\w*|@\".+\")(\s*)(:)(\s*)/,
  169. push: [{
  170. token: [
  171. "storage.type.zig",
  172. "text",
  173. "punctuation.separator.zig",
  174. "keyword.operator.assignment.zig"
  175. ],
  176. regex: /((?:[a-zA-Z_][\w.]*|@\".+\")?)(\s*)(?:(,)|(=)|$)/,
  177. next: "pop"
  178. }, {
  179. include: "#dummy_main"
  180. }]
  181. }],
  182. "#function_call": [{
  183. token: "variable.function.zig",
  184. regex: /\b(?!fn)(?:[a-zA-Z_]\w*|@\".+\")(?=\s*\()/
  185. }],
  186. "#keywords": [{
  187. token: "keyword.control.zig",
  188. regex: /\b(?:while|for|break|return|continue|asm|defer|errdefer|unreachable)\b/
  189. }, {
  190. token: "keyword.control.async.zig",
  191. regex: /\b(?:async|await|suspend|nosuspend|resume)\b/
  192. }, {
  193. token: "keyword.control.conditional.zig",
  194. regex: /\b(?:if|else|switch|try|catch|orelse)\b/
  195. }, {
  196. token: "keyword.control.import.zig",
  197. regex: /\b(?!\w)(?:@import|@cImport|@cInclude)\b/
  198. }, {
  199. token: "keyword.other.usingnamespace.zig",
  200. regex: /\busingnamespace\b/
  201. }],
  202. "#label": [{
  203. token: [
  204. "keyword.control.zig",
  205. "text",
  206. "entity.name.label.zig",
  207. "entity.name.label.zig"
  208. ],
  209. regex: /\b(break|continue)(\s*:\s*)([a-zA-Z_]\w*|@\".+\")\b|\b(?!\d)([a-zA-Z_]\w*|@\".+\")\b(?=\s*:\s*(?:\{|while\b))/
  210. }],
  211. "#operators": [{
  212. token: "keyword.operator.zig",
  213. regex: /\b!\b/
  214. }, {
  215. token: "keyword.operator.logical.zig",
  216. regex: /==|(?:!|>|<)=?/
  217. }, {
  218. token: "keyword.operator.word.zig",
  219. regex: /\b(?:and|or)\b/
  220. }, {
  221. token: "keyword.operator.assignment.zig",
  222. regex: /(?:(?:\+|-|\*)\%?|\/|%|<<|>>|&|\|(?=[^\|])|\^)?=/
  223. }, {
  224. token: "keyword.operator.arithmetic.zig",
  225. regex: /(?:\+|-|\*)\%?|\/(?!\/)|%/
  226. }, {
  227. token: "keyword.operator.bitwise.zig",
  228. regex: /<<|>>|&(?=[a-zA-Z_]|@\")|\|(?=[^\|])|\^|~/
  229. }, {
  230. token: "keyword.operator.other.zig",
  231. regex: /\+\+|\*\*|->|\.\?|\.\*|&(?=[a-zA-Z_]|@\")|\?|\|\||\.{2,3}/
  232. }],
  233. "#param_list": [{
  234. token: [
  235. "variable.parameter.zig",
  236. "text",
  237. "punctuation.separator.zig",
  238. "text"
  239. ],
  240. regex: /([a-zA-Z_]\w*|@\".+\")(\s*)(:)(\s*)/,
  241. push: [{
  242. token: [
  243. "storage.type.zig",
  244. "text",
  245. "punctuation.separator.zig",
  246. "punctuation.section.parens.end.zig"
  247. ],
  248. regex: /((?:[a-zA-Z_][\w.]*|@\".+\")?)(\s*)(?:(,)|(\)))/,
  249. next: "pop"
  250. }, {
  251. include: "#dummy_main"
  252. }, {
  253. token: "storage.type.zig",
  254. regex: /[a-zA-Z_][\w.]*|@\".+\"/
  255. }]
  256. }],
  257. "#punctuation": [{
  258. token: "punctuation.separator.zig",
  259. regex: /,/
  260. }, {
  261. token: "punctuation.terminator.zig",
  262. regex: /;/
  263. }, {
  264. token: "punctuation.section.parens.begin.zig",
  265. regex: /\(/
  266. }, {
  267. token: "punctuation.section.parens.end.zig",
  268. regex: /\)/
  269. }],
  270. "#storage": [{
  271. token: "storage.type.zig",
  272. regex: /\b(?:bool|void|noreturn|type|anyerror|anytype)\b/
  273. }, {
  274. token: "storage.type.integer.zig",
  275. regex: /\b(?!\.)(?:[iu]\d+|[iu]size|comptime_int)\b/
  276. }, {
  277. token: "storage.type.float.zig",
  278. regex: /\b(?:f16|f32|f64|f128|comptime_float)\b/
  279. }, {
  280. token: "storage.type.c_compat.zig",
  281. regex: /\b(?:c_short|c_ushort|c_int|c_uint|c_long|c_ulong|c_longlong|c_ulonglong|c_longdouble|c_void)\b/
  282. }, {
  283. token: [
  284. "storage.type.zig",
  285. "text",
  286. "keyword.operator.zig",
  287. "text",
  288. "storage.type.zig"
  289. ],
  290. regex: /\b(anyframe)\b(\s*)((?:->)?)(\s*)(?:([a-zA-Z_][\w.]*|@\".+\")\b(?!\s*\())?/
  291. }, {
  292. token: "storage.type.function.zig",
  293. regex: /\bfn\b/
  294. }, {
  295. token: "storage.type.test.zig",
  296. regex: /\btest\b/
  297. }, {
  298. token: "storage.type.struct.zig",
  299. regex: /\bstruct\b/
  300. }, {
  301. token: "storage.type.enum.zig",
  302. regex: /\benum\b/
  303. }, {
  304. token: "storage.type.union.zig",
  305. regex: /\bunion\b/
  306. }, {
  307. token: "storage.type.error.zig",
  308. regex: /\berror\b/
  309. }],
  310. "#storage_modifier": [{
  311. token: "storage.modifier.zig",
  312. regex: /\b(?:const|var|extern|packed|export|pub|noalias|inline|noinline|comptime|volatile|align|linksection|threadlocal|allowzero)\b/
  313. }],
  314. "#strings": [{
  315. token: "string.quoted.single.zig",
  316. regex: /\'/,
  317. push: [{
  318. token: "string.quoted.single.zig",
  319. regex: /\'/,
  320. next: "pop"
  321. }, {
  322. include: "#character_escapes"
  323. }, {
  324. token: "invalid.illegal.character.zig",
  325. regex: /\\[^\'][^\']*?/
  326. }, {
  327. defaultToken: "string.quoted.single.zig"
  328. }]
  329. }, {
  330. token: "string.quoted.double.zig",
  331. regex: /c?\"/,
  332. push: [{
  333. token: "string.quoted.double.zig",
  334. regex: /\"/,
  335. next: "pop"
  336. }, {
  337. include: "#character_escapes"
  338. }, {
  339. token: "invalid.illegal.character.zig",
  340. regex: /\\[^\'][^\']*?/
  341. }, {
  342. defaultToken: "string.quoted.double.zig"
  343. }]
  344. }, {
  345. token: "string.quoted.other.zig",
  346. regex: /c?\\\\/,
  347. push: [{
  348. token: "string.quoted.other.zig",
  349. regex: /$/,
  350. next: "pop"
  351. }, {
  352. defaultToken: "string.quoted.other.zig"
  353. }]
  354. }],
  355. "#function_type": [{
  356. token: [
  357. "storage.type.function.zig",
  358. "text",
  359. "punctuation.section.parens.begin.zig"
  360. ],
  361. regex: /\b(fn)(\s*)(\()/,
  362. push: [{
  363. token: [
  364. "text",
  365. "storage.type.zig",
  366. "text",
  367. "keyword.operator.zig",
  368. "text",
  369. "storage.type.zig"
  370. ],
  371. regex: /(\s*)(?:([a-zA-Z_]\w*|@\".+\"))?(\s*)((?:!)?)(\s*)([a-zA-Z_]\w*|@\".+\")/,
  372. next: "pop"
  373. }, {
  374. include: "#label"
  375. }, {
  376. include: "#param_list"
  377. }, {
  378. token: "storage.type.zig",
  379. regex: /[a-zA-Z_]\w*|@\".+\"/
  380. }, {
  381. include: "#dummy_main"
  382. }, {
  383. defaultToken: "meta.function.parameters.zig"
  384. }]
  385. }],
  386. "#function_def": [{
  387. token: [
  388. "text",
  389. "entity.name.function",
  390. "punctuation.section.parens.begin.zig"
  391. ],
  392. regex: /(?=fn\s+)(\s+)([a-zA-Z_]\w*|@\".+\")(\()/,
  393. push: [{
  394. token: [
  395. "text",
  396. "storage.type.zig",
  397. "keyword.operator.zig",
  398. "text",
  399. "storage.type.zig"
  400. ],
  401. regex: /(\s*)((?:[a-zA-Z_][\w.]*|@\".+\")?)((?:!)?)(\s*)(?:([a-zA-Z_][\w.]*|@\".+\")?)/,
  402. next: "pop"
  403. }, {
  404. include: "#label"
  405. }, {
  406. include: "#param_list"
  407. }, {
  408. token: "storage.type.zig",
  409. regex: /[a-zA-Z_][\w.]*|@\".+\"/
  410. }, {
  411. include: "#dummy_main"
  412. }]
  413. }],
  414. "#support": [{
  415. token: "support.function.zig",
  416. regex: /\b@(?!\w|\"|[0-9])[a-zA-Z_]\w*\b/
  417. }],
  418. "#variables": [{
  419. token: "variable.constant.zig",
  420. regex: /\b[_A-Z][_A-Z0-9]+\b/
  421. }, {
  422. token: "entity.name.type.zig",
  423. regex: /\b[_a-zA-Z][_a-zA-Z0-9]*_t\b/
  424. }, {
  425. token: "entity.name.type.zig",
  426. regex: /\b[A-Z][a-zA-Z0-9]*\b/
  427. }, {
  428. token: "variable.zig",
  429. regex: /\b[_a-zA-Z][_a-zA-Z0-9]*\b/
  430. }]
  431. };
  432. this.normalizeRules();
  433. };
  434. ZigHighlightRules.metaData = {
  435. fileTypes: ["zig"],
  436. keyEquivalent: "^~Z",
  437. name: "Zig",
  438. scopeName: "source.zig"
  439. };
  440. oop.inherits(ZigHighlightRules, TextHighlightRules);
  441. exports.ZigHighlightRules = ZigHighlightRules;
  442. });
  443. 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";
  444. var oop = require("../../lib/oop");
  445. var Range = require("../../range").Range;
  446. var BaseFoldMode = require("./fold_mode").FoldMode;
  447. var FoldMode = exports.FoldMode = function (commentRegex) {
  448. if (commentRegex) {
  449. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  450. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  451. }
  452. };
  453. oop.inherits(FoldMode, BaseFoldMode);
  454. (function () {
  455. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  456. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  457. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  458. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  459. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  460. this._getFoldWidgetBase = this.getFoldWidget;
  461. this.getFoldWidget = function (session, foldStyle, row) {
  462. var line = session.getLine(row);
  463. if (this.singleLineBlockCommentRe.test(line)) {
  464. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  465. return "";
  466. }
  467. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  468. if (!fw && this.startRegionRe.test(line))
  469. return "start"; // lineCommentRegionStart
  470. return fw;
  471. };
  472. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  473. var line = session.getLine(row);
  474. if (this.startRegionRe.test(line))
  475. return this.getCommentRegionBlock(session, line, row);
  476. var match = line.match(this.foldingStartMarker);
  477. if (match) {
  478. var i = match.index;
  479. if (match[1])
  480. return this.openingBracketBlock(session, match[1], row, i);
  481. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  482. if (range && !range.isMultiLine()) {
  483. if (forceMultiline) {
  484. range = this.getSectionRange(session, row);
  485. }
  486. else if (foldStyle != "all")
  487. range = null;
  488. }
  489. return range;
  490. }
  491. if (foldStyle === "markbegin")
  492. return;
  493. var match = line.match(this.foldingStopMarker);
  494. if (match) {
  495. var i = match.index + match[0].length;
  496. if (match[1])
  497. return this.closingBracketBlock(session, match[1], row, i);
  498. return session.getCommentFoldRange(row, i, -1);
  499. }
  500. };
  501. this.getSectionRange = function (session, row) {
  502. var line = session.getLine(row);
  503. var startIndent = line.search(/\S/);
  504. var startRow = row;
  505. var startColumn = line.length;
  506. row = row + 1;
  507. var endRow = row;
  508. var maxRow = session.getLength();
  509. while (++row < maxRow) {
  510. line = session.getLine(row);
  511. var indent = line.search(/\S/);
  512. if (indent === -1)
  513. continue;
  514. if (startIndent > indent)
  515. break;
  516. var subRange = this.getFoldWidgetRange(session, "all", row);
  517. if (subRange) {
  518. if (subRange.start.row <= startRow) {
  519. break;
  520. }
  521. else if (subRange.isMultiLine()) {
  522. row = subRange.end.row;
  523. }
  524. else if (startIndent == indent) {
  525. break;
  526. }
  527. }
  528. endRow = row;
  529. }
  530. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  531. };
  532. this.getCommentRegionBlock = function (session, line, row) {
  533. var startColumn = line.search(/\s*$/);
  534. var maxRow = session.getLength();
  535. var startRow = row;
  536. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  537. var depth = 1;
  538. while (++row < maxRow) {
  539. line = session.getLine(row);
  540. var m = re.exec(line);
  541. if (!m)
  542. continue;
  543. if (m[1])
  544. depth--;
  545. else
  546. depth++;
  547. if (!depth)
  548. break;
  549. }
  550. var endRow = row;
  551. if (endRow > startRow) {
  552. return new Range(startRow, startColumn, endRow, line.length);
  553. }
  554. };
  555. }).call(FoldMode.prototype);
  556. });
  557. ace.define("ace/mode/zig",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/zig_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module){"use strict";
  558. var oop = require("../lib/oop");
  559. var TextMode = require("./text").Mode;
  560. var ZigHighlightRules = require("./zig_highlight_rules").ZigHighlightRules;
  561. var FoldMode = require("./folding/cstyle").FoldMode;
  562. var Mode = function () {
  563. this.HighlightRules = ZigHighlightRules;
  564. this.foldingRules = new FoldMode();
  565. this.$behaviour = this.$defaultBehaviour;
  566. };
  567. oop.inherits(Mode, TextMode);
  568. (function () {
  569. this.lineCommentStart = "//";
  570. this.$id = "ace/mode/zig";
  571. }).call(Mode.prototype);
  572. exports.Mode = Mode;
  573. }); (function() {
  574. ace.require(["ace/mode/zig"], function(m) {
  575. if (typeof module == "object" && typeof exports == "object" && module) {
  576. module.exports = m;
  577. }
  578. });
  579. })();