bicep.js 3.8 KB

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