Skip to content

Commit 35c242a

Browse files
bison
1 parent 629ab52 commit 35c242a

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

src/languages/bison.js

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,49 @@
1-
import { insertBefore } from '../util/language-util.js';
21
import c from './c.js';
32

43
/** @type {import('../types.d.ts').LanguageProto<'bison'>} */
54
export default {
65
id: 'bison',
76
base: c,
87
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+
},
2931
},
32+
$rest: 'c',
3033
},
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': /%[%?]|[|:;\[\]<>]/,
4144
},
42-
'punctuation': /%[%?]|[|:;\[\]<>]/,
4345
},
4446
},
45-
});
46-
47-
return {};
47+
};
4848
},
4949
};
50-
51-
/**
52-
* @typedef {import('../types.d.ts').Grammar} Grammar
53-
*/

0 commit comments

Comments
 (0)