prism-bicep.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // based loosely upon: https://github.com/Azure/bicep/blob/main/src/textmate/bicep.tmlanguage
  2. Prism.languages.bicep = {
  3. 'comment': [
  4. {
  5. // multiline comments eg /* ASDF */
  6. pattern: /(^|[^\\])\/\*[\s\S]*?(?:\*\/|$)/,
  7. lookbehind: true,
  8. greedy: true
  9. },
  10. {
  11. // singleline comments eg // ASDF
  12. pattern: /(^|[^\\:])\/\/.*/,
  13. lookbehind: true,
  14. greedy: true
  15. }
  16. ],
  17. 'property': [
  18. {
  19. pattern: /([\r\n][ \t]*)[a-z_]\w*(?=[ \t]*:)/i,
  20. lookbehind: true
  21. },
  22. {
  23. pattern: /([\r\n][ \t]*)'(?:\\.|\$(?!\{)|[^'\\\r\n$])*'(?=[ \t]*:)/,
  24. lookbehind: true,
  25. greedy: true
  26. }
  27. ],
  28. 'string': [
  29. {
  30. pattern: /'''[^'][\s\S]*?'''/,
  31. greedy: true
  32. },
  33. {
  34. pattern: /(^|[^\\'])'(?:\\.|\$(?!\{)|[^'\\\r\n$])*'/,
  35. lookbehind: true,
  36. greedy: true,
  37. }
  38. ],
  39. 'interpolated-string': {
  40. pattern: /(^|[^\\'])'(?:\\.|\$(?:(?!\{)|\{[^{}\r\n]*\})|[^'\\\r\n$])*'/,
  41. lookbehind: true,
  42. greedy: true,
  43. inside: {
  44. 'interpolation': {
  45. pattern: /\$\{[^{}\r\n]*\}/,
  46. inside: {
  47. 'expression': {
  48. pattern: /(^\$\{)[\s\S]+(?=\}$)/,
  49. lookbehind: true
  50. },
  51. 'punctuation': /^\$\{|\}$/,
  52. }
  53. },
  54. 'string': /[\s\S]+/
  55. }
  56. },
  57. 'datatype': {
  58. pattern: /(\b(?:output|param)\b[ \t]+\w+[ \t]+)\w+\b/,
  59. lookbehind: true,
  60. alias: 'class-name'
  61. },
  62. 'boolean': /\b(?:false|true)\b/,
  63. // https://github.com/Azure/bicep/blob/114a3251b4e6e30082a58729f19a8cc4e374ffa6/src/textmate/bicep.tmlanguage#L184
  64. 'keyword': /\b(?:existing|for|if|in|module|null|output|param|resource|targetScope|var)\b/,
  65. 'decorator': /@\w+\b/,
  66. 'function': /\b[a-z_]\w*(?=[ \t]*\()/i,
  67. 'number': /(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:E[+-]?\d+)?/i,
  68. 'operator': /--|\+\+|\*\*=?|=>|&&=?|\|\|=?|[!=]==|<<=?|>>>?=?|[-+*/%&|^!=<>]=?|\.{3}|\?\?=?|\?\.?|[~:]/,
  69. 'punctuation': /[{}[\];(),.:]/,
  70. };
  71. Prism.languages.bicep['interpolated-string'].inside['interpolation'].inside['expression'].inside = Prism.languages.bicep;