|
1 | | -import { insertBefore } from '../util/language-util.js'; |
2 | 1 | import markup from './markup.js'; |
3 | 2 |
|
4 | 3 | /** @type {import('../types.d.ts').LanguageProto<'velocity'>} */ |
5 | 4 | export default { |
6 | 5 | id: 'velocity', |
7 | 6 | base: markup, |
8 | | - grammar ({ base }) { |
| 7 | + grammar () { |
9 | 8 | const vel = { |
10 | 9 | 'variable': { |
11 | 10 | pattern: |
@@ -34,59 +33,59 @@ export default { |
34 | 33 | 'punctuation': vel['punctuation'], |
35 | 34 | }; |
36 | 35 |
|
37 | | - insertBefore(base, 'comment', { |
38 | | - 'unparsed': { |
39 | | - pattern: /(^|[^\\])#\[\[[\s\S]*?\]\]#/, |
40 | | - lookbehind: true, |
41 | | - greedy: true, |
42 | | - inside: { |
43 | | - 'punctuation': /^#\[\[|\]\]#$/, |
| 36 | + return { |
| 37 | + $merge: { |
| 38 | + 'tag': { |
| 39 | + inside: { |
| 40 | + 'attr-value': { |
| 41 | + inside: { |
| 42 | + $rest: 'velocity', |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
44 | 46 | }, |
45 | 47 | }, |
46 | | - 'velocity-comment': [ |
47 | | - { |
48 | | - pattern: /(^|[^\\])#\*[\s\S]*?\*#/, |
49 | | - lookbehind: true, |
50 | | - greedy: true, |
51 | | - alias: 'comment', |
52 | | - }, |
53 | | - { |
54 | | - pattern: /(^|[^\\])##.*/, |
55 | | - lookbehind: true, |
56 | | - greedy: true, |
57 | | - alias: 'comment', |
58 | | - }, |
59 | | - ], |
60 | | - 'directive': { |
61 | | - pattern: |
62 | | - /(^|[^\\](?:\\\\)*)#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})(?:\s*\((?:[^()]|\([^()]*\))*\))?/i, |
63 | | - lookbehind: true, |
64 | | - inside: /** @type {Grammar} */ ({ |
65 | | - 'keyword': { |
66 | | - pattern: /^#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})|\bin\b/, |
| 48 | + $insertBefore: { |
| 49 | + 'comment': { |
| 50 | + 'unparsed': { |
| 51 | + pattern: /(^|[^\\])#\[\[[\s\S]*?\]\]#/, |
| 52 | + lookbehind: true, |
| 53 | + greedy: true, |
| 54 | + inside: { |
| 55 | + 'punctuation': /^#\[\[|\]\]#$/, |
| 56 | + }, |
| 57 | + }, |
| 58 | + 'velocity-comment': [ |
| 59 | + { |
| 60 | + pattern: /(^|[^\\])#\*[\s\S]*?\*#/, |
| 61 | + lookbehind: true, |
| 62 | + greedy: true, |
| 63 | + alias: 'comment', |
| 64 | + }, |
| 65 | + { |
| 66 | + pattern: /(^|[^\\])##.*/, |
| 67 | + lookbehind: true, |
| 68 | + greedy: true, |
| 69 | + alias: 'comment', |
| 70 | + }, |
| 71 | + ], |
| 72 | + 'directive': { |
| 73 | + pattern: |
| 74 | + /(^|[^\\](?:\\\\)*)#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})(?:\s*\((?:[^()]|\([^()]*\))*\))?/i, |
| 75 | + lookbehind: true, |
67 | 76 | inside: { |
68 | | - 'punctuation': /[{}]/, |
| 77 | + 'keyword': { |
| 78 | + pattern: /^#@?(?:[a-z][\w-]*|\{[a-z][\w-]*\})|\bin\b/, |
| 79 | + inside: { |
| 80 | + 'punctuation': /[{}]/, |
| 81 | + }, |
| 82 | + }, |
| 83 | + $rest: vel, |
69 | 84 | }, |
70 | 85 | }, |
71 | | - $rest: /** @type {Grammar['$rest']} */ (vel), |
72 | | - }), |
| 86 | + 'variable': vel['variable'], |
| 87 | + }, |
73 | 88 | }, |
74 | | - 'variable': vel['variable'], |
75 | | - }); |
76 | | - |
77 | | - /** @type {Grammar} */ ( |
78 | | - /** @type {GrammarToken} */ ( |
79 | | - /** @type {Grammar} */ (/** @type {GrammarToken} */ (base['tag']).inside)[ |
80 | | - 'attr-value' |
81 | | - ] |
82 | | - ).inside |
83 | | - ).$rest = 'velocity'; |
84 | | - |
85 | | - return {}; |
| 89 | + }; |
86 | 90 | }, |
87 | 91 | }; |
88 | | - |
89 | | -/** |
90 | | - * @typedef {import('../types.d.ts').Grammar} Grammar |
91 | | - * @typedef {import('../types.d.ts').GrammarToken} GrammarToken |
92 | | - */ |
0 commit comments