bicep.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*!-----------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Version: 0.31.1(337587859b1c171314b40503171188b6cea6a32a)
  4. * Released under the MIT license
  5. * https://github.com/microsoft/monaco-editor/blob/main/LICENSE.txt
  6. *-----------------------------------------------------------------------------*/
  7. // src/basic-languages/bicep/bicep.ts
  8. var bounded = (text) => `\\b${text}\\b`;
  9. var identifierStart = "[_a-zA-Z]";
  10. var identifierContinue = "[_a-zA-Z0-9]";
  11. var identifier = bounded(`${identifierStart}${identifierContinue}*`);
  12. var keywords = [
  13. "targetScope",
  14. "resource",
  15. "module",
  16. "param",
  17. "var",
  18. "output",
  19. "for",
  20. "in",
  21. "if",
  22. "existing"
  23. ];
  24. var namedLiterals = ["true", "false", "null"];
  25. var nonCommentWs = `[ \\t\\r\\n]`;
  26. var numericLiteral = `[0-9]+`;
  27. var conf = {
  28. comments: {
  29. lineComment: "//",
  30. blockComment: ["/*", "*/"]
  31. },
  32. brackets: [
  33. ["{", "}"],
  34. ["[", "]"],
  35. ["(", ")"]
  36. ],
  37. surroundingPairs: [
  38. { open: "{", close: "}" },
  39. { open: "[", close: "]" },
  40. { open: "(", close: ")" },
  41. { open: "'", close: "'" },
  42. { open: "'''", close: "'''" }
  43. ],
  44. autoClosingPairs: [
  45. { open: "{", close: "}" },
  46. { open: "[", close: "]" },
  47. { open: "(", close: ")" },
  48. { open: "'", close: "'", notIn: ["string", "comment"] },
  49. { open: "'''", close: "'''", notIn: ["string", "comment"] }
  50. ],
  51. autoCloseBefore: ":.,=}])' \n ",
  52. indentationRules: {
  53. increaseIndentPattern: new RegExp("^((?!\\/\\/).)*(\\{[^}\"'`]*|\\([^)\"'`]*|\\[[^\\]\"'`]*)$"),
  54. decreaseIndentPattern: new RegExp("^((?!.*?\\/\\*).*\\*/)?\\s*[\\}\\]].*$")
  55. }
  56. };
  57. var language = {
  58. defaultToken: "",
  59. tokenPostfix: ".bicep",
  60. brackets: [
  61. { open: "{", close: "}", token: "delimiter.curly" },
  62. { open: "[", close: "]", token: "delimiter.square" },
  63. { open: "(", close: ")", token: "delimiter.parenthesis" }
  64. ],
  65. symbols: /[=><!~?:&|+\-*/^%]+/,
  66. keywords,
  67. namedLiterals,
  68. escapes: `\\\\(u{[0-9A-Fa-f]+}|n|r|t|\\\\|'|\\\${)`,
  69. tokenizer: {
  70. root: [{ include: "@expression" }, { include: "@whitespace" }],
  71. stringVerbatim: [
  72. { regex: `(|'|'')[^']`, action: { token: "string" } },
  73. { regex: `'''`, action: { token: "string.quote", next: "@pop" } }
  74. ],
  75. stringLiteral: [
  76. { regex: `\\\${`, action: { token: "delimiter.bracket", next: "@bracketCounting" } },
  77. { regex: `[^\\\\'$]+`, action: { token: "string" } },
  78. { regex: "@escapes", action: { token: "string.escape" } },
  79. { regex: `\\\\.`, action: { token: "string.escape.invalid" } },
  80. { regex: `'`, action: { token: "string", next: "@pop" } }
  81. ],
  82. bracketCounting: [
  83. { regex: `{`, action: { token: "delimiter.bracket", next: "@bracketCounting" } },
  84. { regex: `}`, action: { token: "delimiter.bracket", next: "@pop" } },
  85. { include: "expression" }
  86. ],
  87. comment: [
  88. { regex: `[^\\*]+`, action: { token: "comment" } },
  89. { regex: `\\*\\/`, action: { token: "comment", next: "@pop" } },
  90. { regex: `[\\/*]`, action: { token: "comment" } }
  91. ],
  92. whitespace: [
  93. { regex: nonCommentWs },
  94. { regex: `\\/\\*`, action: { token: "comment", next: "@comment" } },
  95. { regex: `\\/\\/.*$`, action: { token: "comment" } }
  96. ],
  97. expression: [
  98. { regex: `'''`, action: { token: "string.quote", next: "@stringVerbatim" } },
  99. { regex: `'`, action: { token: "string.quote", next: "@stringLiteral" } },
  100. { regex: numericLiteral, action: { token: "number" } },
  101. {
  102. regex: identifier,
  103. action: {
  104. cases: {
  105. "@keywords": { token: "keyword" },
  106. "@namedLiterals": { token: "keyword" },
  107. "@default": { token: "identifier" }
  108. }
  109. }
  110. }
  111. ]
  112. }
  113. };
  114. export {
  115. conf,
  116. language
  117. };