grammar-well 1.3.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +165 -0
- package/README.md +76 -560
- package/build/generator/artifacts/basic.d.ts +7 -0
- package/build/generator/artifacts/basic.js +24 -0
- package/build/generator/artifacts/basic.js.map +1 -0
- package/build/generator/artifacts/lexer.d.ts +13 -0
- package/build/generator/artifacts/lexer.js +204 -0
- package/build/generator/artifacts/lexer.js.map +1 -0
- package/build/{compiler/generator → generator}/artifacts/lr.d.ts +14 -14
- package/build/{compiler/generator → generator}/artifacts/lr.js +18 -22
- package/build/generator/artifacts/lr.js.map +1 -0
- package/build/generator/builtin/json.d.ts +183 -0
- package/build/generator/builtin/json.js +124 -0
- package/build/generator/builtin/json.js.map +1 -0
- package/build/generator/builtin/registry.json +1 -0
- package/build/generator/builtin/whitespace.d.ts +61 -0
- package/build/generator/builtin/whitespace.js +37 -0
- package/build/generator/builtin/whitespace.js.map +1 -0
- package/build/generator/generator.d.ts +38 -0
- package/build/generator/generator.js +368 -0
- package/build/generator/generator.js.map +1 -0
- package/build/generator/grammars/index.d.ts +2 -0
- package/build/generator/grammars/index.js +3 -0
- package/build/generator/grammars/index.js.map +1 -0
- package/build/generator/grammars/v1.d.ts +1190 -0
- package/build/generator/grammars/v1.js +614 -0
- package/build/generator/grammars/v1.js.map +1 -0
- package/build/generator/grammars/v2.d.ts +1367 -0
- package/build/generator/grammars/v2.js +695 -0
- package/build/generator/grammars/v2.js.map +1 -0
- package/build/generator/import-resolvers/auto.d.ts +2 -0
- package/build/generator/import-resolvers/auto.js +11 -0
- package/build/generator/import-resolvers/auto.js.map +1 -0
- package/build/generator/import-resolvers/browser.d.ts +7 -0
- package/build/generator/import-resolvers/browser.js +13 -0
- package/build/generator/import-resolvers/browser.js.map +1 -0
- package/build/generator/import-resolvers/default.d.ts +2 -0
- package/build/generator/import-resolvers/default.js +11 -0
- package/build/generator/import-resolvers/default.js.map +1 -0
- package/build/generator/import-resolvers/filesystem.d.ts +7 -0
- package/build/generator/import-resolvers/filesystem.js +15 -0
- package/build/generator/import-resolvers/filesystem.js.map +1 -0
- package/build/generator/index.d.ts +3 -0
- package/build/generator/index.js +4 -0
- package/build/generator/index.js.map +1 -0
- package/build/generator/state.d.ts +28 -0
- package/build/generator/state.js +73 -0
- package/build/generator/state.js.map +1 -0
- package/build/generator/stringify/common.d.ts +22 -0
- package/build/generator/stringify/common.js +83 -0
- package/build/generator/stringify/common.js.map +1 -0
- package/build/generator/stringify/exports/javascript.d.ts +3 -0
- package/build/generator/stringify/exports/javascript.js +26 -0
- package/build/generator/stringify/exports/javascript.js.map +1 -0
- package/build/generator/stringify/exports/json.d.ts +2 -0
- package/build/generator/stringify/exports/json.js +4 -0
- package/build/generator/stringify/exports/json.js.map +1 -0
- package/build/generator/stringify/exports/registry.d.ts +20 -0
- package/build/generator/stringify/exports/registry.js +17 -0
- package/build/generator/stringify/exports/registry.js.map +1 -0
- package/build/generator/stringify/exports/typescript.d.ts +2 -0
- package/build/generator/stringify/exports/typescript.js +16 -0
- package/build/generator/stringify/exports/typescript.js.map +1 -0
- package/build/generator/stringify/grammar/v2.d.ts +20 -0
- package/build/generator/stringify/grammar/v2.js +211 -0
- package/build/generator/stringify/grammar/v2.js.map +1 -0
- package/build/generator/stringify/javascript.d.ts +13 -0
- package/build/generator/stringify/javascript.js +83 -0
- package/build/generator/stringify/javascript.js.map +1 -0
- package/build/index.d.ts +7 -6
- package/build/index.js +7 -24
- package/build/index.js.map +1 -1
- package/build/lexers/character-lexer.d.ts +2 -2
- package/build/lexers/character-lexer.js +1 -5
- package/build/lexers/character-lexer.js.map +1 -1
- package/build/lexers/stateful-lexer.d.ts +12 -17
- package/build/lexers/stateful-lexer.js +38 -186
- package/build/lexers/stateful-lexer.js.map +1 -1
- package/build/lexers/token-buffer.d.ts +8 -8
- package/build/lexers/token-buffer.js +1 -5
- package/build/lexers/token-buffer.js.map +1 -1
- package/build/parser/algorithms/cyk.d.ts +6 -6
- package/build/parser/algorithms/cyk.js +10 -13
- package/build/parser/algorithms/cyk.js.map +1 -1
- package/build/parser/algorithms/earley.d.ts +7 -7
- package/build/parser/algorithms/earley.js +7 -11
- package/build/parser/algorithms/earley.js.map +1 -1
- package/build/parser/algorithms/lrk/algorithm.d.ts +3 -3
- package/build/parser/algorithms/lrk/algorithm.js +10 -13
- package/build/parser/algorithms/lrk/algorithm.js.map +1 -1
- package/build/parser/algorithms/lrk/bimap.js +1 -5
- package/build/parser/algorithms/lrk/bimap.js.map +1 -1
- package/build/parser/algorithms/lrk/canonical-collection.d.ts +7 -7
- package/build/parser/algorithms/lrk/canonical-collection.js +11 -15
- package/build/parser/algorithms/lrk/canonical-collection.js.map +1 -1
- package/build/parser/algorithms/lrk/closure.d.ts +3 -3
- package/build/parser/algorithms/lrk/closure.js +3 -7
- package/build/parser/algorithms/lrk/closure.js.map +1 -1
- package/build/parser/algorithms/lrk/stack.d.ts +6 -6
- package/build/parser/algorithms/lrk/stack.js +1 -5
- package/build/parser/algorithms/lrk/stack.js.map +1 -1
- package/build/parser/algorithms/lrk/state.d.ts +5 -5
- package/build/parser/algorithms/lrk/state.js +1 -2
- package/build/parser/parse.d.ts +10 -0
- package/build/parser/parse.js +34 -0
- package/build/parser/parse.js.map +1 -0
- package/build/parser/parser.d.ts +6 -17
- package/build/parser/parser.js +26 -42
- package/build/parser/parser.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -0
- package/build/typings/ast.d.ts +134 -0
- package/build/typings/ast.js +3 -0
- package/build/typings/ast.js.map +1 -0
- package/build/typings/common.d.ts +4 -0
- package/build/typings/common.js +2 -0
- package/build/typings/common.js.map +1 -0
- package/build/typings/generator.d.ts +58 -0
- package/build/typings/generator.js +3 -0
- package/build/typings/generator.js.map +1 -0
- package/build/typings/index.d.ts +43 -0
- package/build/typings/index.js +5 -0
- package/build/typings/index.js.map +1 -0
- package/build/typings/runtime.d.ts +70 -0
- package/build/typings/runtime.js +2 -0
- package/build/typings/runtime.js.map +1 -0
- package/build/utility/format.d.ts +1 -0
- package/build/utility/format.js +12 -0
- package/build/utility/format.js.map +1 -0
- package/build/utility/formatter.d.ts +1 -0
- package/build/utility/formatter.js +12 -0
- package/build/utility/formatter.js.map +1 -0
- package/build/utility/general.d.ts +1 -1
- package/build/utility/general.js +5 -13
- package/build/utility/general.js.map +1 -1
- package/build/utility/index.d.ts +4 -1
- package/build/utility/index.js +4 -17
- package/build/utility/index.js.map +1 -1
- package/build/utility/lint.d.ts +2 -2
- package/build/utility/lint.js +2 -6
- package/build/utility/lint.js.map +1 -1
- package/build/utility/migrate.d.ts +1 -0
- package/build/utility/migrate.js +10 -0
- package/build/utility/migrate.js.map +1 -0
- package/build/utility/monarch.d.ts +2 -2
- package/build/utility/monarch.js +33 -38
- package/build/utility/monarch.js.map +1 -1
- package/build/utility/parsing.d.ts +6 -0
- package/build/utility/parsing.js +26 -0
- package/build/utility/parsing.js.map +1 -0
- package/build/utility/text-format.d.ts +6 -6
- package/build/utility/text-format.js +2 -6
- package/build/utility/text-format.js.map +1 -1
- package/package.json +17 -24
- package/src/generator/artifacts/basic.ts +26 -0
- package/src/generator/artifacts/lexer.ts +228 -0
- package/src/{compiler/generator → generator}/artifacts/lr.ts +25 -24
- package/src/generator/builtin/character.well +7 -0
- package/src/generator/builtin/json.well +85 -0
- package/src/generator/builtin/number.well +21 -0
- package/src/generator/builtin/registry.json +1 -0
- package/src/generator/builtin/string.well +54 -0
- package/src/generator/builtin/whitespace.well +16 -0
- package/src/generator/generator.ts +401 -0
- package/src/generator/grammars/index.ts +2 -0
- package/src/generator/grammars/v1.ts +620 -0
- package/src/generator/grammars/v1.well +422 -0
- package/src/generator/grammars/v2.ts +701 -0
- package/src/generator/grammars/v2.well +413 -0
- package/src/generator/import-resolvers/auto.ts +12 -0
- package/src/generator/import-resolvers/browser.ts +13 -0
- package/src/generator/import-resolvers/filesystem.ts +18 -0
- package/src/generator/index.ts +3 -0
- package/src/generator/state.ts +89 -0
- package/src/generator/stringify/common.ts +90 -0
- package/src/generator/stringify/exports/javascript.ts +29 -0
- package/src/generator/stringify/exports/json.ts +5 -0
- package/src/generator/stringify/exports/registry.ts +20 -0
- package/src/generator/stringify/exports/typescript.ts +17 -0
- package/src/generator/stringify/grammar/v2.ts +223 -0
- package/src/generator/stringify/javascript.ts +94 -0
- package/src/index.ts +7 -6
- package/src/lexers/character-lexer.ts +2 -2
- package/src/lexers/stateful-lexer.ts +46 -203
- package/src/lexers/token-buffer.ts +3 -3
- package/src/parser/algorithms/cyk.ts +13 -12
- package/src/parser/algorithms/earley.ts +10 -10
- package/src/parser/algorithms/lrk/algorithm.ts +8 -7
- package/src/parser/algorithms/lrk/canonical-collection.ts +14 -14
- package/src/parser/algorithms/lrk/closure.ts +6 -6
- package/src/parser/algorithms/lrk/stack.ts +6 -6
- package/src/parser/algorithms/lrk/state.ts +5 -5
- package/src/parser/parse.ts +45 -0
- package/src/typings/ast.ts +148 -0
- package/src/typings/common.ts +2 -0
- package/src/typings/generator.ts +62 -0
- package/src/typings/index.ts +38 -0
- package/src/typings/runtime.ts +82 -0
- package/src/utility/format.ts +12 -0
- package/src/utility/general.ts +1 -2
- package/src/utility/index.ts +4 -1
- package/src/utility/lint.ts +5 -5
- package/src/utility/monarch.ts +34 -34
- package/src/utility/parsing.ts +30 -0
- package/src/utility/text-format.ts +7 -7
- package/.eslintrc.cjs +0 -14
- package/bootstrap.ts +0 -45
- package/build/compiler/builtin.json +0 -1
- package/build/compiler/compiler.d.ts +0 -50
- package/build/compiler/compiler.js +0 -249
- package/build/compiler/compiler.js.map +0 -1
- package/build/compiler/generator/artifacts/lr.js.map +0 -1
- package/build/compiler/generator/artifacts/standard.d.ts +0 -7
- package/build/compiler/generator/artifacts/standard.js +0 -28
- package/build/compiler/generator/artifacts/standard.js.map +0 -1
- package/build/compiler/generator/generator.d.ts +0 -24
- package/build/compiler/generator/generator.js +0 -217
- package/build/compiler/generator/generator.js.map +0 -1
- package/build/compiler/gwell.d.ts +0 -1112
- package/build/compiler/gwell.js +0 -576
- package/build/compiler/gwell.js.map +0 -1
- package/build/compiler/import-resolver.d.ts +0 -15
- package/build/compiler/import-resolver.js +0 -37
- package/build/compiler/import-resolver.js.map +0 -1
- package/build/compiler/index.d.ts +0 -2
- package/build/compiler/index.js +0 -19
- package/build/compiler/index.js.map +0 -1
- package/build/compiler/outputs/javascript.d.ts +0 -3
- package/build/compiler/outputs/javascript.js +0 -29
- package/build/compiler/outputs/javascript.js.map +0 -1
- package/build/compiler/outputs/json.d.ts +0 -2
- package/build/compiler/outputs/json.js +0 -8
- package/build/compiler/outputs/json.js.map +0 -1
- package/build/compiler/outputs/typescript.d.ts +0 -2
- package/build/compiler/outputs/typescript.js +0 -21
- package/build/compiler/outputs/typescript.js.map +0 -1
- package/build/parser/algorithms/lr.d.ts +0 -7
- package/build/parser/algorithms/lr.js +0 -108
- package/build/parser/algorithms/lr.js.map +0 -5
- package/build/parser/algorithms/lr0.d.ts +0 -7
- package/build/parser/algorithms/lr0.js +0 -156
- package/build/parser/algorithms/lr0.js.map +0 -1
- package/build/typings.d.ts +0 -226
- package/build/typings.js +0 -3
- package/build/typings.js.map +0 -1
- package/src/compiler/builtin/json.gwell +0 -74
- package/src/compiler/builtin/number.gwell +0 -20
- package/src/compiler/builtin/string.gwell +0 -48
- package/src/compiler/builtin/whitespace.gwell +0 -10
- package/src/compiler/builtin.json +0 -1
- package/src/compiler/compiler.ts +0 -265
- package/src/compiler/generator/artifacts/standard.ts +0 -26
- package/src/compiler/generator/generator.ts +0 -237
- package/src/compiler/gwell.gwell +0 -294
- package/src/compiler/gwell.js +0 -578
- package/src/compiler/import-resolver.ts +0 -36
- package/src/compiler/index.ts +0 -2
- package/src/compiler/outputs/javascript.ts +0 -27
- package/src/compiler/outputs/json.ts +0 -5
- package/src/compiler/outputs/typescript.ts +0 -18
- package/src/parser/parser.ts +0 -77
- package/src/typings.ts +0 -248
- package/testing.ts +0 -18
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { GeneratorGrammarRule, } from "../../../typings";
|
|
2
|
-
import { Generator } from "../generator";
|
|
3
|
-
|
|
4
|
-
export class StandardGrammar {
|
|
5
|
-
|
|
6
|
-
constructor(private generator: Generator) { }
|
|
7
|
-
|
|
8
|
-
serialize(depth: number = 0) {
|
|
9
|
-
if (!this.generator.state.grammar) {
|
|
10
|
-
return null;
|
|
11
|
-
}
|
|
12
|
-
return Generator.Pretty({
|
|
13
|
-
start: JSON.stringify(this.generator.state.grammar.start),
|
|
14
|
-
rules: this.serializeGrammarRules(depth + 1)
|
|
15
|
-
}, depth);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private serializeGrammarRules(depth: number = 0) {
|
|
19
|
-
const map = {};
|
|
20
|
-
for (const rule in this.generator.state.grammar.rules) {
|
|
21
|
-
map[rule] = this.generator.state.grammar.rules[rule].map(v => this.generator.serializeGrammarRule(v))
|
|
22
|
-
}
|
|
23
|
-
return Generator.Pretty(map, depth);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}
|
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
import { Dictionary, GeneratorState, GeneratorGrammarRule, GeneratorGrammarSymbol, LexerConfig, LexerStateDefinition } from "../../typings";
|
|
2
|
-
import { LRParseTableBuilder } from "./artifacts/lr";
|
|
3
|
-
import { StandardGrammar } from "./artifacts/standard";
|
|
4
|
-
|
|
5
|
-
const PostProcessors = {
|
|
6
|
-
"join": "({data}) => data.join('')",
|
|
7
|
-
"concat": "({data}) => data[0].concat([data[1]])",
|
|
8
|
-
"null": "() => null",
|
|
9
|
-
"first": "({data}) => data[0]"
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export class Generator {
|
|
13
|
-
|
|
14
|
-
state: GeneratorState = {
|
|
15
|
-
grammar: {
|
|
16
|
-
start: '',
|
|
17
|
-
config: {},
|
|
18
|
-
rules: {},
|
|
19
|
-
uuids: {},
|
|
20
|
-
},
|
|
21
|
-
lexer: null,
|
|
22
|
-
head: [],
|
|
23
|
-
body: [],
|
|
24
|
-
config: {},
|
|
25
|
-
version: 'unknown',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
serializeHead() {
|
|
29
|
-
if (this.state.config.noscript)
|
|
30
|
-
return '';
|
|
31
|
-
return this.state.head.join('\n');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
serializeBody() {
|
|
35
|
-
if (this.state.config.noscript)
|
|
36
|
-
return '';
|
|
37
|
-
return this.state.body.join('\n');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
serializeLanguage(depth: number = 0) {
|
|
41
|
-
const serialier = new StandardGrammar(this);
|
|
42
|
-
let lr = null;
|
|
43
|
-
|
|
44
|
-
if ('lr' in this.state.config) {
|
|
45
|
-
const table = new LRParseTableBuilder(this);
|
|
46
|
-
lr = Generator.Pretty({
|
|
47
|
-
k: "0",
|
|
48
|
-
table: table.serialize(depth + 2)
|
|
49
|
-
}, depth + 1);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return Generator.Pretty({
|
|
53
|
-
grammar: serialier.serialize(depth + 1),
|
|
54
|
-
lexer: this.serializeLexerConfig(depth + 1),
|
|
55
|
-
lr
|
|
56
|
-
}, depth);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
merge(state: GeneratorState) {
|
|
60
|
-
// TODO: Resolve Conflicting Rules and UUIDS
|
|
61
|
-
Object.assign(this.state.grammar.rules, state.grammar.rules);
|
|
62
|
-
this.state.grammar.start = state.grammar.start || this.state.grammar.start;
|
|
63
|
-
this.state.grammar.config.postprocessorDefault = state.grammar.config.postprocessorDefault || this.state.grammar.config.postprocessorDefault;
|
|
64
|
-
this.state.grammar.config.postprocessorOverride = state.grammar.config.postprocessorOverride || this.state.grammar.config.postprocessorOverride;
|
|
65
|
-
|
|
66
|
-
if (state.lexer) {
|
|
67
|
-
if (this.state.lexer) {
|
|
68
|
-
Object.assign(this.state.lexer.states, state.lexer.states);
|
|
69
|
-
} else {
|
|
70
|
-
this.state.lexer = state.lexer;
|
|
71
|
-
}
|
|
72
|
-
this.state.lexer.start = state.lexer.start || this.state.lexer.start;
|
|
73
|
-
}
|
|
74
|
-
this.state.head.push(...state.head);
|
|
75
|
-
this.state.body.push(...state.body);
|
|
76
|
-
Object.assign(this.state.config, state.config);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
grammarUUID(name: string) {
|
|
80
|
-
this.state.grammar.uuids[name] = (this.state.grammar.uuids[name] || 0) + 1;
|
|
81
|
-
return name + 'x' + this.state.grammar.uuids[name];
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
addGrammarRule(rule: GeneratorGrammarRule) {
|
|
85
|
-
this.state.grammar.rules[rule.name] = this.state.grammar.rules[rule.name] || [];
|
|
86
|
-
this.state.grammar.rules[rule.name].push(rule);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
addLexerState(state: LexerStateDefinition) {
|
|
90
|
-
this.state.lexer.states[state.name] = this.state.lexer.states[state.name] || { name: state.name, rules: [] }
|
|
91
|
-
const target = this.state.lexer.states[state.name];
|
|
92
|
-
target.default = typeof state.default == 'string' ? state.default : target.default;
|
|
93
|
-
target.unmatched = typeof state.unmatched == 'string' ? state.unmatched : target.unmatched;
|
|
94
|
-
target.rules.push(...state.rules);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
serializePostProcess(postprocess: GeneratorGrammarRule['postprocess'], alias: Dictionary<number>) {
|
|
98
|
-
postprocess = this.state.grammar.config.postprocessorOverride || postprocess || this.state.grammar.config.postprocessorDefault;
|
|
99
|
-
if (!postprocess)
|
|
100
|
-
return null;
|
|
101
|
-
if ('builtin' in postprocess)
|
|
102
|
-
return PostProcessors[postprocess.builtin];
|
|
103
|
-
if (this.state.config.noscript)
|
|
104
|
-
return;
|
|
105
|
-
if (typeof postprocess == 'string')
|
|
106
|
-
return postprocess;
|
|
107
|
-
if ('js' in postprocess)
|
|
108
|
-
return postprocess.js;
|
|
109
|
-
if ('template' in postprocess)
|
|
110
|
-
return this.templatePostProcess(postprocess.template, alias);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
private templatePostProcess(templateBody: string, alias: { [key: string]: number }) {
|
|
114
|
-
for (const key in alias) {
|
|
115
|
-
templateBody = templateBody.replace(new RegExp('(?:\\$)' + key + '(?![a-zA-Z\\d\\$_])'), `data[${alias[key]}]`);
|
|
116
|
-
}
|
|
117
|
-
return "({data}) => { return " + templateBody.replace(/\$(\d+)/g, "data[$1]") + "; }";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
private serializeLexerConfig(depth: number = 0) {
|
|
121
|
-
if (!this.state.lexer)
|
|
122
|
-
return null;
|
|
123
|
-
|
|
124
|
-
if (typeof this.state.lexer === 'string')
|
|
125
|
-
return this.state.lexer;
|
|
126
|
-
|
|
127
|
-
return Generator.Pretty({
|
|
128
|
-
start: JSON.stringify(this.state.lexer.start),
|
|
129
|
-
states: this.serializeLexerConfigStates(depth + 1)
|
|
130
|
-
}, depth);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
private serializeLexerConfigStates(depth: number) {
|
|
134
|
-
const map = {};
|
|
135
|
-
for (const key in this.state.lexer.states) {
|
|
136
|
-
const state = this.state.lexer.states[key];
|
|
137
|
-
map[state.name] = Generator.Pretty({
|
|
138
|
-
name: JSON.stringify(state.name),
|
|
139
|
-
default: state.default ? JSON.stringify(state.default) : null,
|
|
140
|
-
unmatched: state.unmatched ? JSON.stringify(state.unmatched) : null,
|
|
141
|
-
rules: this.serializeLexerConfigStateRules(state.rules, depth + 2)
|
|
142
|
-
}, depth + 1);
|
|
143
|
-
}
|
|
144
|
-
return Generator.Pretty(map, depth);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private serializeLexerConfigStateRules(rules: LexerConfig['states'][0]['rules'], depth: number) {
|
|
148
|
-
const ary = rules.map(rule => {
|
|
149
|
-
if ('import' in rule)
|
|
150
|
-
return Generator.Pretty({ import: JSON.stringify(rule.import) }, -1)
|
|
151
|
-
return Generator.Pretty({
|
|
152
|
-
when: Generator.SerializeSymbol(rule.when as any),
|
|
153
|
-
type: JSON.stringify(rule.type),
|
|
154
|
-
tag: JSON.stringify(rule.tag),
|
|
155
|
-
pop: JSON.stringify(rule.pop),
|
|
156
|
-
before: JSON.stringify(rule.before),
|
|
157
|
-
open: JSON.stringify(rule.open),
|
|
158
|
-
close: JSON.stringify(rule.close),
|
|
159
|
-
highlight: JSON.stringify(rule.highlight),
|
|
160
|
-
set: JSON.stringify(rule.set),
|
|
161
|
-
inset: JSON.stringify(rule.inset),
|
|
162
|
-
goto: JSON.stringify(rule.goto),
|
|
163
|
-
}, -1);
|
|
164
|
-
});
|
|
165
|
-
return Generator.Pretty(ary, depth);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
serializeGrammarRule(rule: GeneratorGrammarRule) {
|
|
169
|
-
const symbols = [];
|
|
170
|
-
const alias = {};
|
|
171
|
-
for (let i = 0; i < rule.symbols.length; i++) {
|
|
172
|
-
symbols.push(Generator.SerializeSymbol(rule.symbols[i]));
|
|
173
|
-
if (rule.symbols[i].alias) {
|
|
174
|
-
alias[rule.symbols[i].alias] = i;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return Generator.Pretty({
|
|
179
|
-
name: JSON.stringify(rule.name),
|
|
180
|
-
symbols: Generator.Pretty(symbols, -1),
|
|
181
|
-
postprocess: this.serializePostProcess(rule.postprocess, alias)
|
|
182
|
-
}, -1);
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
static NewLine(depth: number) {
|
|
186
|
-
return '\n' + ' '.repeat(depth * 4);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
static Pretty(obj: string[] | { [key: string]: string | (string[]) }, depth = 0) {
|
|
190
|
-
if (Array.isArray(obj)) {
|
|
191
|
-
let r = `[`;
|
|
192
|
-
for (let i = 0; i < obj.length; i++) {
|
|
193
|
-
const value = obj[i];
|
|
194
|
-
r += `${depth >= 0 ? Generator.NewLine(depth + 1) : ' '}${value}${(Generator.IsVal(obj[i + 1]) ? ',' : '')}`;
|
|
195
|
-
}
|
|
196
|
-
r += `${depth >= 0 ? Generator.NewLine(depth) : ' '}]`;
|
|
197
|
-
return r;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
let r = `{`;
|
|
201
|
-
const keys = Object.keys(obj).filter(v => Generator.IsVal(obj[v]));
|
|
202
|
-
const prefix = depth >= 0 ? Generator.NewLine(depth + 1) : ' ';
|
|
203
|
-
for (let i = 0; i < keys.length; i++) {
|
|
204
|
-
const key = /[a-z_][a-z\d_$]*/i.test(keys[i]) ? keys[i] : JSON.stringify(keys[i]);
|
|
205
|
-
const value = Array.isArray(obj[keys[i]]) ? Generator.Pretty(obj[keys[i]] as string[], depth >= 0 ? depth + 1 : -1) : obj[keys[i]];
|
|
206
|
-
const suffix = (Generator.IsVal(obj[keys[i + 1]]) ? ',' : '');
|
|
207
|
-
r += `${prefix}${key}: ${value}${suffix}`;
|
|
208
|
-
}
|
|
209
|
-
r += `${depth >= 0 ? Generator.NewLine(depth) : ' '}}`;
|
|
210
|
-
return r;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
static IsVal(value) {
|
|
214
|
-
return typeof value !== 'undefined' && value !== null;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
static SerializeSymbol(s: GeneratorGrammarSymbol) {
|
|
218
|
-
if (typeof s === 'string') {
|
|
219
|
-
return JSON.stringify(s);
|
|
220
|
-
} else if ('rule' in s) {
|
|
221
|
-
return JSON.stringify(s.rule);
|
|
222
|
-
} else if ('regex' in s) {
|
|
223
|
-
return `/${s.regex}/${s.flags || ''}`;
|
|
224
|
-
} else if ('token' in s) {
|
|
225
|
-
return `{ token: ${JSON.stringify(s.token)} }`;
|
|
226
|
-
} else if ('literal' in s) {
|
|
227
|
-
return `{ literal: ${JSON.stringify(s.literal)} }`;
|
|
228
|
-
} else {
|
|
229
|
-
return JSON.stringify(s);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
static SymbolIsTerminal(s: GeneratorGrammarSymbol) {
|
|
234
|
-
return !(typeof s === 'string' || 'rule' in s);
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
}
|
package/src/compiler/gwell.gwell
DELETED
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
lexer: {{
|
|
2
|
-
start: "start"
|
|
3
|
-
|
|
4
|
-
start ->
|
|
5
|
-
- import: string, js, ws, comment, l_scolon, l_star
|
|
6
|
-
- when: /lexer(?![a-zA-Z\d_])/ tag: "T_WORD" goto: lexer highlight: "type"
|
|
7
|
-
- when: /grammar(?![a-zA-Z\d_])/ tag: "T_WORD" goto: grammar highlight: "type"
|
|
8
|
-
- when: /config(?![a-zA-Z\d_])/ tag: "T_WORD" goto: config highlight: "type"
|
|
9
|
-
- import: kv
|
|
10
|
-
config ->
|
|
11
|
-
- import: ws, l_colon
|
|
12
|
-
- when: "{{" tag: "L_TEMPLATEL" set: config_inner
|
|
13
|
-
config_inner ->
|
|
14
|
-
- import: comment, kv
|
|
15
|
-
- when: "}}" tag: "L_TEMPLATER" pop: 1
|
|
16
|
-
grammar ->
|
|
17
|
-
- import: ws, l_colon
|
|
18
|
-
- when: "{{" tag: "L_TEMPLATEL" set: grammar_inner
|
|
19
|
-
grammar_inner ->
|
|
20
|
-
- import: comment, js, js_template, ws, regex, l_qmark, l_plus, l_star, kv, l_colon, l_comma, l_pipe, l_parenl, l_parenr, l_arrow, l_dsign, l_dash
|
|
21
|
-
- when: "}}" tag: "L_TEMPLATER" pop: 1
|
|
22
|
-
lexer ->
|
|
23
|
-
- import: ws, l_colon
|
|
24
|
-
- when: "{{" tag: "L_TEMPLATEL" set: lexer_inner
|
|
25
|
-
lexer_inner ->
|
|
26
|
-
- import: ws, comment, regex, l_comma, l_arrow, l_dash, kv, js
|
|
27
|
-
- when: "}}" tag: "L_TEMPLATER" pop: 1
|
|
28
|
-
js ->
|
|
29
|
-
- when: "${" tag: "L_JSL" goto: js_wrap
|
|
30
|
-
js_wrap ->
|
|
31
|
-
default: "T_JSBODY"
|
|
32
|
-
unmatched: "T_JSBODY"
|
|
33
|
-
- import: jsignore
|
|
34
|
-
- when: "{" tag: "T_JSBODY" goto: js_literal
|
|
35
|
-
- when: "}" tag: "L_JSR" pop: 1
|
|
36
|
-
js_literal ->
|
|
37
|
-
default: "T_JSBODY"
|
|
38
|
-
unmatched: "T_JSBODY"
|
|
39
|
-
- import: jsignore
|
|
40
|
-
- when: "{" tag: "T_JSBODY" goto: js_literal
|
|
41
|
-
- when: "}" tag: "T_JSBODY" pop: 1
|
|
42
|
-
js_template ->
|
|
43
|
-
- when: "{{" tag: "L_TEMPLATEL" goto: js_template_inner
|
|
44
|
-
js_template_inner ->
|
|
45
|
-
default: "T_JSBODY"
|
|
46
|
-
unmatched: "T_JSBODY"
|
|
47
|
-
- import: jsignore
|
|
48
|
-
- when: "{" tag: "T_JSBODY" goto: js_literal
|
|
49
|
-
- when: "}}" tag: "L_TEMPLATER" pop: 1
|
|
50
|
-
kv ->
|
|
51
|
-
- import: string, ws, word, l_colon, integer
|
|
52
|
-
jsignore ->
|
|
53
|
-
- when: /"(?:[^"\\\r\n]|\\.)*"/ tag: "T_JSBODY"
|
|
54
|
-
- when: /'(?:[^'\\\r\n]|\\.)*'/ tag: "T_JSBODY"
|
|
55
|
-
- when: /`(?:[^`\\]|\\.)*`/ tag: "T_JSBODY"
|
|
56
|
-
- when: /\/(?:[^\/\\\r\n]|\\.)+\/[gmiyu]*/ tag: "T_JSBODY"
|
|
57
|
-
- when: /\/\/[^\n]*/ tag: "T_JSBODY"
|
|
58
|
-
- when: /\/\*.*\*\// tag: "T_JSBODY"
|
|
59
|
-
string ->
|
|
60
|
-
- when: /"(?:[^"\\\r\n]|\\.)*"/ tag: "T_STRING" highlight: "string"
|
|
61
|
-
string2 ->
|
|
62
|
-
- when: /'(?:[^'\\\r\n]|\\.)*'/ tag: "T_STRING" highlight: "string"
|
|
63
|
-
string3 ->
|
|
64
|
-
- when: /`(?:[^`\\]|\\.)*`/ tag: "T_STRING" highlight: "string"
|
|
65
|
-
regex ->
|
|
66
|
-
- when: /\/(?:[^\/\\\r\n]|\\.)+\// tag: "T_REGEX" highlight: "regexp"
|
|
67
|
-
integer ->
|
|
68
|
-
- when: /\d+/ tag: "T_INTEGER" highlight: "number"
|
|
69
|
-
word ->
|
|
70
|
-
- when: /[a-zA-Z_][a-zA-Z_\d]*/ tag: "T_WORD"
|
|
71
|
-
ws ->
|
|
72
|
-
- when: /\s+/ tag: "T_WS"
|
|
73
|
-
l_colon ->
|
|
74
|
-
- when: ":" tag: "L_COLON" highlight: "keyword"
|
|
75
|
-
l_scolon ->
|
|
76
|
-
- when: ";" tag: "L_SCOLON"
|
|
77
|
-
l_qmark ->
|
|
78
|
-
- when: "?" tag: "L_QMARK"
|
|
79
|
-
l_plus ->
|
|
80
|
-
- when: "+" tag: "L_PLUS"
|
|
81
|
-
l_star ->
|
|
82
|
-
- when: "*" tag: "L_STAR"
|
|
83
|
-
l_comma ->
|
|
84
|
-
- when: "," tag: "L_COMMA"
|
|
85
|
-
l_pipe ->
|
|
86
|
-
- when: "|" tag: "L_PIPE" highlight: "keyword"
|
|
87
|
-
l_parenl ->
|
|
88
|
-
- when: "(" tag: "L_PARENL"
|
|
89
|
-
l_parenr ->
|
|
90
|
-
- when: ")" tag: "L_PARENR"
|
|
91
|
-
l_templatel ->
|
|
92
|
-
- when: "{{" tag: "L_TEMPLATEL"
|
|
93
|
-
l_templater ->
|
|
94
|
-
- when: "}}" tag: "L_TEMPLATER"
|
|
95
|
-
l_arrow ->
|
|
96
|
-
- when: "->" tag: "L_ARROW" highlight: "keyword"
|
|
97
|
-
l_dsign ->
|
|
98
|
-
- when: "$" tag: "L_DSIGN"
|
|
99
|
-
l_dash ->
|
|
100
|
-
- when: "-" tag: "L_DASH"
|
|
101
|
-
comment ->
|
|
102
|
-
- when: /\/\/[^\n]*/ tag: "T_COMMENT" highlight: "comment"
|
|
103
|
-
commentmulti ->
|
|
104
|
-
- when: /\/\*.*\*\// tag: "T_COMMENT" highlight: "comment"
|
|
105
|
-
|
|
106
|
-
}}
|
|
107
|
-
|
|
108
|
-
grammar: {{
|
|
109
|
-
|
|
110
|
-
main ->
|
|
111
|
-
_ section_list _ : {{ $1 }}
|
|
112
|
-
|
|
113
|
-
section_list ->
|
|
114
|
-
section : {{ [$0] }}
|
|
115
|
-
| section T_WS section_list : {{ [$0].concat($2) }}
|
|
116
|
-
|
|
117
|
-
section ->
|
|
118
|
-
K_CONFIG _ L_COLON _ L_TEMPLATEL _ kv_list:list _ L_TEMPLATER : {{ { config: Object.assign(...$list) } }}
|
|
119
|
-
| K_IMPORT _ L_STAR _ K_FROM __ T_WORD:import _ L_SCOLON : {{ { import: $import } }}
|
|
120
|
-
| K_IMPORT _ L_STAR _ K_FROM __ T_STRING:import _ L_SCOLON : {{ { import: $import, path: true } }}
|
|
121
|
-
| K_IMPORT _ L_STAR _ "as" _ T_WORD:alias _ K_FROM __ T_WORD:import _ L_SCOLON : {{ { import: $import, alias: $alias} }}
|
|
122
|
-
| K_IMPORT _ L_STAR _ "as" _ T_WORD:alias _ K_FROM __ T_STRING:import _ L_SCOLON : {{ { import: $import, path: true, alias: $alias} }}
|
|
123
|
-
| K_LEXER _ L_COLON _ L_TEMPLATEL _ lexer:lexer _ L_TEMPLATER : {{ { lexer: Object.assign(...$lexer) } }}
|
|
124
|
-
| K_GRAMMAR _ L_COLON _ L_TEMPLATEL _ grammar:grammar _ L_TEMPLATER : {{ { grammar: $grammar } }}
|
|
125
|
-
| K_BODY _ L_COLON _ T_JS:js : {{ { body: $js } }}
|
|
126
|
-
| K_BODY _ L_COLON _ T_STRING:js : {{ { body: $js, path: true } }}
|
|
127
|
-
| K_HEAD _ L_COLON _ T_JS:js : {{ { head: $js } }}
|
|
128
|
-
| K_HEAD _ L_COLON _ T_STRING:js : {{ { head: $js, path: true } }}
|
|
129
|
-
|
|
130
|
-
lexer ->
|
|
131
|
-
kv_list _ state_list : {{ $0.concat({ states: $2 }) }}
|
|
132
|
-
| state_list : {{ [{ states: $0 }] }}
|
|
133
|
-
|
|
134
|
-
state_list ->
|
|
135
|
-
state : {{ data }}
|
|
136
|
-
| state _ state_list : {{ [$0].concat($2) }}
|
|
137
|
-
|
|
138
|
-
state ->
|
|
139
|
-
state_declare _ state_definition : {{ Object.assign({ name: $0 }, $2) }}
|
|
140
|
-
|
|
141
|
-
state_declare ->
|
|
142
|
-
T_WORD _ L_ARROW : {{ $0 }}
|
|
143
|
-
|
|
144
|
-
state_definition ->
|
|
145
|
-
kv_list _ token_list : {{ Object.assign(...$0, { rules: $2 }) }}
|
|
146
|
-
| token_list : {{ { rules: $0 } }}
|
|
147
|
-
|
|
148
|
-
token_list ->
|
|
149
|
-
token : {{ data }}
|
|
150
|
-
| token _ token_list : {{ [$0].concat($2) }}
|
|
151
|
-
|
|
152
|
-
token ->
|
|
153
|
-
L_DASH _ K_IMPORT _ L_COLON _ word_list : {{ { import: $6 } }}
|
|
154
|
-
| L_DASH _ token_definition_list : {{ Object.assign(...$2) }}
|
|
155
|
-
|
|
156
|
-
token_definition_list ->
|
|
157
|
-
token_definition : {{ data }}
|
|
158
|
-
| token_definition _ token_definition_list : {{ [$0].concat($2) }}
|
|
159
|
-
|
|
160
|
-
token_definition ->
|
|
161
|
-
K_TAG _ L_COLON _ string_list : {{ { tag: $4 } }}
|
|
162
|
-
| K_WHEN _ L_COLON _ T_STRING : {{ { when: $4 } }}
|
|
163
|
-
| K_WHEN _ L_COLON _ T_REGEX : {{ { when: $4 } }}
|
|
164
|
-
| K_OPEN _ L_COLON _ T_STRING : {{ { open: $4 } }}
|
|
165
|
-
| K_CLOSE _ L_COLON _ T_STRING : {{ { close: $4 } }}
|
|
166
|
-
| K_BEFORE _ L_COLON _ T_STRING : {{ { when: $4, before:true } }}
|
|
167
|
-
| K_BEFORE _ L_COLON _ T_REGEX : {{ { when: $4, before:true } }}
|
|
168
|
-
| K_POP : {{ { pop: 1 } }}
|
|
169
|
-
| K_POP _ L_COLON _ T_INTEGER : {{ { pop: parseInt($4) } }}
|
|
170
|
-
| K_POP _ L_COLON _ K_ALL : {{ { pop: "all" } }}
|
|
171
|
-
| K_HIGHLIGHT _ L_COLON _ T_STRING : {{ { highlight: $4 } }}
|
|
172
|
-
| K_EMBED _ L_COLON _ T_STRING : {{ { embed: $4 } }}
|
|
173
|
-
| K_UNEMBED : {{ { unembed: true } }}
|
|
174
|
-
| K_INSET : {{ { inset: 1 } }}
|
|
175
|
-
| K_INSET _ L_COLON _ T_INTEGER : {{ { inset: parseInt($4) } }}
|
|
176
|
-
| K_SET _ L_COLON _ T_WORD : {{ { set: $4 } }}
|
|
177
|
-
| K_GOTO _ L_COLON _ T_WORD : {{ { goto: $4 } }}
|
|
178
|
-
| K_TYPE _ L_COLON _ T_STRING : {{ { type: $4 } }}
|
|
179
|
-
|
|
180
|
-
grammar ->
|
|
181
|
-
kv_list _ grammar_rule_list : {{ { config: Object.assign(...$0), rules: $2 } }}
|
|
182
|
-
| grammar_rule_list : {{ { rules: $0 } }}
|
|
183
|
-
|
|
184
|
-
grammar_rule_list ->
|
|
185
|
-
grammar_rule : {{ [$0] }}
|
|
186
|
-
| grammar_rule _ grammar_rule_list : {{ [$0].concat($2) }}
|
|
187
|
-
|
|
188
|
-
grammar_rule ->
|
|
189
|
-
T_WORD _ L_ARROW _ expression_list : {{ { name: $0, expressions: $4 } }}
|
|
190
|
-
| T_WORD __ L_COLON _ T_JS:js _ L_ARROW _ expression_list:expressions : {{ { name: $0, expressions: $expressions, postprocess: $js } }}
|
|
191
|
-
| T_WORD __ L_COLON _ T_GRAMMAR_TEMPLATE:template _ L_ARROW _ expression_list:expressions : {{ { name: $0, expressions: $expressions, postprocess: $template } }}
|
|
192
|
-
|
|
193
|
-
expression_list ->
|
|
194
|
-
expression
|
|
195
|
-
| expression_list _ L_PIPE _ expression : {{ $0.concat([$4]) }}
|
|
196
|
-
|
|
197
|
-
expression ->
|
|
198
|
-
expression_symbol_list : {{ { symbols: $0 } }}
|
|
199
|
-
| expression_symbol_list __ L_COLON _ T_JS:js : {{ { symbols: $0, postprocess: $js } }}
|
|
200
|
-
| expression_symbol_list __ L_COLON _ T_GRAMMAR_TEMPLATE:template : {{ { symbols: $0, postprocess: $template } }}
|
|
201
|
-
|
|
202
|
-
expression_symbol_list ->
|
|
203
|
-
expression_symbol
|
|
204
|
-
| expression_symbol_list T_WS expression_symbol : {{ $0.concat([$2]) }}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
expression_symbol ->
|
|
208
|
-
expression_symbol_match : {{ $0 }}
|
|
209
|
-
| expression_symbol_match L_COLON T_WORD : {{ { ...$0, alias: $2 } }}
|
|
210
|
-
| expression_symbol_match expression_repeater : {{ { expression: $0, repeat: $1 } }}
|
|
211
|
-
| expression_symbol_match expression_repeater L_COLON T_WORD : {{ { expression: $0, repeat: $1, alias: $4 } }}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
expression_symbol_match ->
|
|
215
|
-
T_WORD : {{ { rule: $0 } }}
|
|
216
|
-
| T_STRING "i"? : {{ { literal: $0, insensitive: !!$1 } }}
|
|
217
|
-
| L_DSIGN T_WORD : {{ { token: $1} }}
|
|
218
|
-
| L_DSIGN T_STRING : {{ { token: $1} }}
|
|
219
|
-
| T_REGEX : {{ $0 }}
|
|
220
|
-
| L_PARENL _ expression_list _ L_PARENR : {{ { subexpression: $2 } }}
|
|
221
|
-
| T_JS : {{ $0 }}
|
|
222
|
-
|
|
223
|
-
expression_repeater : {{ $0[0].value }} ->
|
|
224
|
-
L_QMARK
|
|
225
|
-
| L_PLUS
|
|
226
|
-
| L_STAR
|
|
227
|
-
|
|
228
|
-
kv_list ->
|
|
229
|
-
kv : {{ data }}
|
|
230
|
-
| kv _ kv_list : {{ [$0].concat($2) }}
|
|
231
|
-
|
|
232
|
-
kv ->
|
|
233
|
-
T_WORD _ L_COLON _ ( T_WORD| T_STRING| T_INTEGER | T_JS | T_GRAMMAR_TEMPLATE) : {{ { [$0]: $4[0] } }}
|
|
234
|
-
|
|
235
|
-
string_list ->
|
|
236
|
-
T_STRING : {{ [$0] }}
|
|
237
|
-
| T_STRING _ L_COMMA _ string_list : {{ [$0].concat($4) }}
|
|
238
|
-
|
|
239
|
-
word_list ->
|
|
240
|
-
T_WORD : {{ [$0] }}
|
|
241
|
-
| T_WORD _ L_COMMA _ word_list : {{ [$0].concat($4) }}
|
|
242
|
-
|
|
243
|
-
_ ->
|
|
244
|
-
( T_WS | T_COMMENT )* : {{ null }}
|
|
245
|
-
|
|
246
|
-
__ ->
|
|
247
|
-
( T_WS | T_COMMENT )+ : {{ null }}
|
|
248
|
-
|
|
249
|
-
L_COLON -> $L_COLON
|
|
250
|
-
L_SCOLON -> $L_SCOLON
|
|
251
|
-
L_QMARK -> $L_QMARK
|
|
252
|
-
L_PLUS -> $L_PLUS
|
|
253
|
-
L_STAR -> $L_STAR
|
|
254
|
-
L_COMMA -> $L_COMMA
|
|
255
|
-
L_PIPE -> $L_PIPE
|
|
256
|
-
L_PARENL -> $L_PARENL
|
|
257
|
-
L_PARENR -> $L_PARENR
|
|
258
|
-
L_TEMPLATEL -> $L_TEMPLATEL
|
|
259
|
-
L_TEMPLATER -> $L_TEMPLATER
|
|
260
|
-
L_ARROW -> $L_ARROW
|
|
261
|
-
L_DSIGN -> $L_DSIGN
|
|
262
|
-
L_DASH -> $L_DASH
|
|
263
|
-
|
|
264
|
-
K_ALL -> "all"
|
|
265
|
-
K_TAG -> "tag"
|
|
266
|
-
K_FROM -> "from"
|
|
267
|
-
K_TYPE -> "type"
|
|
268
|
-
K_WHEN -> "when"
|
|
269
|
-
K_POP -> "pop"
|
|
270
|
-
K_BEFORE -> "before"
|
|
271
|
-
K_OPEN -> "open"
|
|
272
|
-
K_CLOSE -> "close"
|
|
273
|
-
K_HIGHLIGHT -> "highlight"
|
|
274
|
-
K_EMBED -> "embed"
|
|
275
|
-
K_UNEMBED -> "unembed"
|
|
276
|
-
K_INSET -> "inset"
|
|
277
|
-
K_SET -> "set"
|
|
278
|
-
K_GOTO -> "goto"
|
|
279
|
-
K_CONFIG -> "config"
|
|
280
|
-
K_LEXER -> "lexer"
|
|
281
|
-
K_GRAMMAR -> "grammar"
|
|
282
|
-
K_IMPORT -> "import"
|
|
283
|
-
K_BODY -> "body"
|
|
284
|
-
K_HEAD -> "head"
|
|
285
|
-
|
|
286
|
-
T_JS -> $L_JSL $T_JSBODY* $L_JSR : {{ { js: $1.map(v=>v.value).join('') } }}
|
|
287
|
-
T_GRAMMAR_TEMPLATE -> $L_TEMPLATEL _ $T_JSBODY* _ $L_TEMPLATER : {{ { template: $2.map(v=>v.value).join('').trim() } }}
|
|
288
|
-
T_STRING -> $T_STRING : {{ JSON.parse($0.value) }}
|
|
289
|
-
T_WORD -> $T_WORD : {{ $0.value }}
|
|
290
|
-
T_REGEX -> $T_REGEX /[gmiuy]/* : {{ { regex: $0.value.replace(/\\\\\//g,'/').slice(1,-1), flags: $1.map(v=>v.value).join('').trim() } }}
|
|
291
|
-
T_COMMENT -> $T_COMMENT
|
|
292
|
-
T_INTEGER -> $T_INTEGER : {{ $0.value }}
|
|
293
|
-
T_WS -> $T_WS : {{ null }}
|
|
294
|
-
}}
|