|
1 | | -import { insertBefore } from '../util/language-util.js'; |
2 | 1 | import c from './c.js'; |
3 | 2 |
|
4 | 3 | /** @type {import('../types.d.ts').LanguageProto<'bison'>} */ |
5 | 4 | export default { |
6 | 5 | id: 'bison', |
7 | 6 | base: c, |
8 | 7 | grammar ({ base }) { |
9 | | - insertBefore(base, 'comment', { |
10 | | - 'bison': { |
11 | | - // This should match all the beginning of the file |
12 | | - // including the prologue(s), the bison declarations and |
13 | | - // the grammar rules. |
14 | | - pattern: /^(?:[^%]|%(?!%))*%%[\s\S]*?%%/, |
15 | | - inside: { |
16 | | - 'c': { |
17 | | - // Allow for one level of nested braces |
18 | | - pattern: /%\{[\s\S]*?%\}|\{(?:\{[^}]*\}|[^{}])*\}/, |
19 | | - inside: /** @type {Grammar} */ ({ |
20 | | - 'delimiter': { |
21 | | - pattern: /^%?\{|%?\}$/, |
22 | | - alias: 'punctuation', |
23 | | - }, |
24 | | - 'bison-variable': { |
25 | | - pattern: /[$@](?:<[^\s>]+>)?[\w$]+/, |
26 | | - alias: 'variable', |
27 | | - inside: { |
28 | | - 'punctuation': /<|>/, |
| 8 | + return { |
| 9 | + $insert: { |
| 10 | + 'bison': { |
| 11 | + $before: 'comment', |
| 12 | + // This should match all the beginning of the file |
| 13 | + // including the prologue(s), the bison declarations and |
| 14 | + // the grammar rules. |
| 15 | + pattern: /^(?:[^%]|%(?!%))*%%[\s\S]*?%%/, |
| 16 | + inside: { |
| 17 | + 'c': { |
| 18 | + // Allow for one level of nested braces |
| 19 | + pattern: /%\{[\s\S]*?%\}|\{(?:\{[^}]*\}|[^{}])*\}/, |
| 20 | + inside: { |
| 21 | + 'delimiter': { |
| 22 | + pattern: /^%?\{|%?\}$/, |
| 23 | + alias: 'punctuation', |
| 24 | + }, |
| 25 | + 'bison-variable': { |
| 26 | + pattern: /[$@](?:<[^\s>]+>)?[\w$]+/, |
| 27 | + alias: 'variable', |
| 28 | + inside: { |
| 29 | + 'punctuation': /<|>/, |
| 30 | + }, |
29 | 31 | }, |
| 32 | + $rest: 'c', |
30 | 33 | }, |
31 | | - $rest: /** @type {Grammar['$rest']} */ ('c'), |
32 | | - }), |
33 | | - }, |
34 | | - 'comment': base.comment, |
35 | | - 'string': base.string, |
36 | | - 'property': /\S+(?=:)/, |
37 | | - 'keyword': /%\w+/, |
38 | | - 'number': { |
39 | | - pattern: /(^|[^@])\b(?:0x[\da-f]+|\d+)/i, |
40 | | - lookbehind: true, |
| 34 | + }, |
| 35 | + 'comment': base.comment, |
| 36 | + 'string': base.string, |
| 37 | + 'property': /\S+(?=:)/, |
| 38 | + 'keyword': /%\w+/, |
| 39 | + 'number': { |
| 40 | + pattern: /(^|[^@])\b(?:0x[\da-f]+|\d+)/i, |
| 41 | + lookbehind: true, |
| 42 | + }, |
| 43 | + 'punctuation': /%[%?]|[|:;\[\]<>]/, |
41 | 44 | }, |
42 | | - 'punctuation': /%[%?]|[|:;\[\]<>]/, |
43 | 45 | }, |
44 | 46 | }, |
45 | | - }); |
46 | | - |
47 | | - return {}; |
| 47 | + }; |
48 | 48 | }, |
49 | 49 | }; |
50 | | - |
51 | | -/** |
52 | | - * @typedef {import('../types.d.ts').Grammar} Grammar |
53 | | - */ |
0 commit comments