leaf.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Language: Leaf
  3. Description: A Swift-based templating language created for the Vapor project.
  4. Website: https://docs.vapor.codes/leaf/overview
  5. Category: template
  6. */
  7. function leaf(hljs) {
  8. const IDENT = /([A-Za-z_][A-Za-z_0-9]*)?/;
  9. const LITERALS = [
  10. 'true',
  11. 'false',
  12. 'in'
  13. ];
  14. const PARAMS = {
  15. scope: 'params',
  16. begin: /\(/,
  17. end: /\)(?=\:?)/,
  18. endsParent: true,
  19. relevance: 7,
  20. contains: [
  21. {
  22. scope: 'string',
  23. begin: '"',
  24. end: '"'
  25. },
  26. {
  27. scope: 'keyword',
  28. match: LITERALS.join("|"),
  29. },
  30. {
  31. scope: 'variable',
  32. match: /[A-Za-z_][A-Za-z_0-9]*/
  33. },
  34. {
  35. scope: 'operator',
  36. match: /\+|\-|\*|\/|\%|\=\=|\=|\!|\>|\<|\&\&|\|\|/
  37. }
  38. ]
  39. };
  40. const INSIDE_DISPATCH = {
  41. match: [
  42. IDENT,
  43. /(?=\()/,
  44. ],
  45. scope: {
  46. 1: "keyword"
  47. },
  48. contains: [ PARAMS ]
  49. };
  50. PARAMS.contains.unshift(INSIDE_DISPATCH);
  51. return {
  52. name: 'Leaf',
  53. contains: [
  54. // #ident():
  55. {
  56. match: [
  57. /#+/,
  58. IDENT,
  59. /(?=\()/,
  60. ],
  61. scope: {
  62. 1: "punctuation",
  63. 2: "keyword"
  64. },
  65. // will start up after the ending `)` match from line ~44
  66. // just to grab the trailing `:` if we can match it
  67. starts: {
  68. contains: [
  69. {
  70. match: /\:/,
  71. scope: "punctuation"
  72. }
  73. ]
  74. },
  75. contains: [
  76. PARAMS
  77. ],
  78. },
  79. // #ident or #ident:
  80. {
  81. match: [
  82. /#+/,
  83. IDENT,
  84. /:?/,
  85. ],
  86. scope: {
  87. 1: "punctuation",
  88. 2: "keyword",
  89. 3: "punctuation"
  90. }
  91. },
  92. ]
  93. };
  94. }
  95. export { leaf as default };