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
|
@@ -0,0 +1,422 @@
|
|
|
1
|
+
lexer {
|
|
2
|
+
start: "start"
|
|
3
|
+
|
|
4
|
+
[start]
|
|
5
|
+
- import string, js, ws, comment, l_scolon, l_star
|
|
6
|
+
- when r:{lexer(?![a-zA-Z\d_])} tag "T_WORD" highlight "type" goto lexer
|
|
7
|
+
- when r:{grammar(?![a-zA-Z\d_])} tag "T_WORD" highlight "type" goto grammar
|
|
8
|
+
- when r:{config(?![a-zA-Z\d_])} tag "T_WORD" highlight "type" goto config
|
|
9
|
+
- import kv
|
|
10
|
+
|
|
11
|
+
[config]
|
|
12
|
+
- import ws, l_colon
|
|
13
|
+
- when "{{" tag "L_TEMPLATEL" set config_inner
|
|
14
|
+
|
|
15
|
+
[config_inner]
|
|
16
|
+
- import comment, kv
|
|
17
|
+
- when "}}" tag "L_TEMPLATER" pop
|
|
18
|
+
|
|
19
|
+
[grammar]
|
|
20
|
+
- import ws, l_colon
|
|
21
|
+
- when "{{" tag "L_TEMPLATEL" set grammar_inner
|
|
22
|
+
|
|
23
|
+
[grammar_inner]
|
|
24
|
+
- 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
|
|
25
|
+
- when "}}" tag "L_TEMPLATER" pop
|
|
26
|
+
|
|
27
|
+
[lexer]
|
|
28
|
+
- import ws, l_colon
|
|
29
|
+
- when "{{" tag "L_TEMPLATEL" set lexer_inner
|
|
30
|
+
|
|
31
|
+
[lexer_inner]
|
|
32
|
+
- import ws, comment, regex, l_comma, l_arrow, l_dash, kv, js
|
|
33
|
+
- when "}}" tag "L_TEMPLATER" pop
|
|
34
|
+
|
|
35
|
+
[js]
|
|
36
|
+
- when "${" tag "L_JSL" goto js_wrap
|
|
37
|
+
|
|
38
|
+
[js_wrap]
|
|
39
|
+
default: tag "T_JSBODY";
|
|
40
|
+
unmatched: tag "T_JSBODY";
|
|
41
|
+
- import jsignore
|
|
42
|
+
- when "{" tag "T_JSBODY" goto js_literal
|
|
43
|
+
- when "}" tag "L_JSR" pop
|
|
44
|
+
|
|
45
|
+
[js_literal]
|
|
46
|
+
default: tag "T_JSBODY";
|
|
47
|
+
unmatched: tag "T_JSBODY";
|
|
48
|
+
- import jsignore
|
|
49
|
+
- when "{" tag "T_JSBODY" goto js_literal
|
|
50
|
+
- when "}" tag "T_JSBODY" pop
|
|
51
|
+
|
|
52
|
+
[js_template]
|
|
53
|
+
- when "{{" tag "L_TEMPLATEL" goto js_template_inner
|
|
54
|
+
|
|
55
|
+
[js_template_inner]
|
|
56
|
+
default: tag "T_JSBODY";
|
|
57
|
+
unmatched: tag "T_JSBODY";
|
|
58
|
+
- import jsignore
|
|
59
|
+
- when "{" tag "T_JSBODY" goto js_literal
|
|
60
|
+
- when "}}" tag "L_TEMPLATER" pop
|
|
61
|
+
|
|
62
|
+
[kv]
|
|
63
|
+
- import string, ws, word, l_colon, integer
|
|
64
|
+
|
|
65
|
+
[jsignore]
|
|
66
|
+
- when r:{"(?:[^"\\\r\n]|\\.)*"} tag "T_JSBODY"
|
|
67
|
+
- when r:{'(?:[^'\\\r\n]|\\.)*'} tag "T_JSBODY"
|
|
68
|
+
- when r:{`(?:[^`\\]|\\.)*`} tag "T_JSBODY"
|
|
69
|
+
- when r:{/(?:[^/\\\r\n]|\\.)+/[gmiyu]*} tag "T_JSBODY"
|
|
70
|
+
- when r:{//[^\n]*} tag "T_JSBODY"
|
|
71
|
+
- when r:{/\*.*\*/} tag "T_JSBODY"
|
|
72
|
+
|
|
73
|
+
[string]
|
|
74
|
+
- when r:{"(?:[^"\\\r\n]|\\.)*"} tag "T_STRING" highlight "string"
|
|
75
|
+
|
|
76
|
+
[string2]
|
|
77
|
+
- when r:{'(?:[^'\\\r\n]|\\.)*'} tag "T_STRING" highlight "string"
|
|
78
|
+
|
|
79
|
+
[string3]
|
|
80
|
+
- when r:{`(?:[^`\\]|\\.)*`} tag "T_STRING" highlight "string"
|
|
81
|
+
|
|
82
|
+
[regex]
|
|
83
|
+
- when r:{\/(?:[^\/\\\r\n]|\\.)+\/} tag "T_REGEX" highlight "regexp"
|
|
84
|
+
|
|
85
|
+
[integer]
|
|
86
|
+
- when r:{\d+} tag "T_INTEGER" highlight "number"
|
|
87
|
+
|
|
88
|
+
[word]
|
|
89
|
+
- when r:{[a-zA-Z_][a-zA-Z_\d]*} tag "T_WORD"
|
|
90
|
+
|
|
91
|
+
[ws]
|
|
92
|
+
- when r:{\s+} tag "T_WS"
|
|
93
|
+
|
|
94
|
+
[l_colon]
|
|
95
|
+
- when ":" tag "L_COLON" highlight "keyword"
|
|
96
|
+
|
|
97
|
+
[l_scolon]
|
|
98
|
+
- when ";" tag "L_SCOLON"
|
|
99
|
+
|
|
100
|
+
[l_qmark]
|
|
101
|
+
- when "?" tag "L_QMARK"
|
|
102
|
+
|
|
103
|
+
[l_plus]
|
|
104
|
+
- when "+" tag "L_PLUS"
|
|
105
|
+
|
|
106
|
+
[l_star]
|
|
107
|
+
- when "*" tag "L_STAR"
|
|
108
|
+
|
|
109
|
+
[l_comma]
|
|
110
|
+
- when "," tag "L_COMMA"
|
|
111
|
+
|
|
112
|
+
[l_pipe]
|
|
113
|
+
- when "|" tag "L_PIPE" highlight "keyword"
|
|
114
|
+
|
|
115
|
+
[l_parenl]
|
|
116
|
+
- when "(" tag "L_PARENL"
|
|
117
|
+
|
|
118
|
+
[l_parenr]
|
|
119
|
+
- when ")" tag "L_PARENR"
|
|
120
|
+
|
|
121
|
+
[l_templatel]
|
|
122
|
+
- when "{{" tag "L_TEMPLATEL"
|
|
123
|
+
|
|
124
|
+
[l_templater]
|
|
125
|
+
- when "}}" tag "L_TEMPLATER"
|
|
126
|
+
|
|
127
|
+
[l_arrow]
|
|
128
|
+
- when "->" tag "L_ARROW" highlight "keyword"
|
|
129
|
+
|
|
130
|
+
[l_dsign]
|
|
131
|
+
- when "$" tag "L_DSIGN"
|
|
132
|
+
|
|
133
|
+
[l_dash]
|
|
134
|
+
- when "-" tag "L_DASH"
|
|
135
|
+
|
|
136
|
+
[comment]
|
|
137
|
+
- when r:{//[^\n]*} tag "T_COMMENT" highlight "comment"
|
|
138
|
+
|
|
139
|
+
[commentmulti]
|
|
140
|
+
- when r:{/\*.*\*/} tag "T_COMMENT" highlight "comment"
|
|
141
|
+
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
grammar {
|
|
145
|
+
|
|
146
|
+
[main]
|
|
147
|
+
| _ section_list _ => ( $1 )
|
|
148
|
+
|
|
149
|
+
[section_list]
|
|
150
|
+
| section => ( [$0] )
|
|
151
|
+
| section T_WS section_list => ( [$0].concat($2) )
|
|
152
|
+
|
|
153
|
+
[section]
|
|
154
|
+
| K_CONFIG _ L_COLON _ L_TEMPLATEL _ kv_list@list _ L_TEMPLATER => ( { config: Object.assign(...$list) } )
|
|
155
|
+
| K_IMPORT _ L_STAR _ K_FROM __ T_WORD@import _ L_SCOLON => ( { import: $import } )
|
|
156
|
+
| K_IMPORT _ L_STAR _ K_FROM __ T_STRING@import _ L_SCOLON => ( { import: $import, path: true } )
|
|
157
|
+
| K_IMPORT _ L_STAR _ "as" _ T_WORD@alias _ K_FROM __ T_WORD@import _ L_SCOLON => ( { import: $import, alias: $alias} )
|
|
158
|
+
| K_IMPORT _ L_STAR _ "as" _ T_WORD@alias _ K_FROM __ T_STRING@import _ L_SCOLON => ( { import: $import, path: true, alias: $alias} )
|
|
159
|
+
| K_LEXER _ L_COLON _ L_TEMPLATEL _ lexer@lexer _ L_TEMPLATER => ( { lexer: Object.assign(...$lexer) } )
|
|
160
|
+
| K_GRAMMAR _ L_COLON _ L_TEMPLATEL _ grammar@grammar _ L_TEMPLATER => ( { grammar: $grammar } )
|
|
161
|
+
| K_BODY _ L_COLON _ T_JS@js => ( { lifecycle: "new", js: $js } )
|
|
162
|
+
| K_BODY _ L_COLON _ T_STRING@js => ( { lifecycle: "new", js: $js, path: true } )
|
|
163
|
+
| K_HEAD _ L_COLON _ T_JS@js => ( { lifecycle:"import", "js": $js } )
|
|
164
|
+
| K_HEAD _ L_COLON _ T_STRING@js => ( { lifecycle:"import", "js": $js, path: true } )
|
|
165
|
+
|
|
166
|
+
[lexer]
|
|
167
|
+
| kv_list _ state_list => ( $0.concat({ states: $2 }) )
|
|
168
|
+
| state_list => ( [{ states: $0 }] )
|
|
169
|
+
|
|
170
|
+
[state_list]
|
|
171
|
+
| state => ( [$0] )
|
|
172
|
+
| state _ state_list => ( [$0].concat($2) )
|
|
173
|
+
|
|
174
|
+
[state]
|
|
175
|
+
| state_declare _ state_definition => ( { name: $0, state: $2 } )
|
|
176
|
+
|
|
177
|
+
[state_declare]
|
|
178
|
+
| T_WORD _ L_ARROW => ( $0 )
|
|
179
|
+
|
|
180
|
+
[state_definition]
|
|
181
|
+
| state_definition_kv_list _ token_list => ( Object.assign(...$0, { rules: $2 }) )
|
|
182
|
+
| token_list => ( { rules: $0 } )
|
|
183
|
+
|
|
184
|
+
[state_definition_kv_list]
|
|
185
|
+
| state_definition_kv => ( data )
|
|
186
|
+
| state_definition_kv _ state_definition_kv_list => ( [$0].concat($2) )
|
|
187
|
+
|
|
188
|
+
[state_definition_kv] => ( { tag: $4 } )
|
|
189
|
+
| "default" _ ":" _ T_WORD
|
|
190
|
+
| "default" _ ":" _ T_STRING
|
|
191
|
+
| "unmatched" _ ":" _ T_WORD
|
|
192
|
+
| "unmatched" _ ":" _ T_STRING
|
|
193
|
+
|
|
194
|
+
[token_list]
|
|
195
|
+
| token => ( data )
|
|
196
|
+
| token _ token_list => ( [$0].concat($2) )
|
|
197
|
+
|
|
198
|
+
[token]
|
|
199
|
+
| L_DASH _ K_IMPORT _ L_COLON _ word_list => ( { import: $6 } )
|
|
200
|
+
| L_DASH _ token_definition_list => ( Object.assign(...$2) )
|
|
201
|
+
|
|
202
|
+
[token_definition_list]
|
|
203
|
+
| token_definition => ( data )
|
|
204
|
+
| token_definition _ token_definition_list => ( [$0].concat($2) )
|
|
205
|
+
|
|
206
|
+
[token_definition]
|
|
207
|
+
| K_TAG _ L_COLON _ string_list => ( { tag: $4 } )
|
|
208
|
+
| K_WHEN _ L_COLON _ T_STRING => ( { when: $4 } )
|
|
209
|
+
| K_WHEN _ L_COLON _ T_REGEX => ( { when: $4 } )
|
|
210
|
+
| K_OPEN _ L_COLON _ T_STRING => ( { open: $4 } )
|
|
211
|
+
| K_CLOSE _ L_COLON _ T_STRING => ( { close: $4 } )
|
|
212
|
+
| K_BEFORE _ L_COLON _ T_STRING => ( { when: $4, before: true } )
|
|
213
|
+
| K_BEFORE _ L_COLON _ T_REGEX => ( { when: $4, before: true } )
|
|
214
|
+
| K_POP => ( { pop: 1 } )
|
|
215
|
+
| K_POP _ L_COLON _ T_INTEGER => ( { pop: parseInt($4) } )
|
|
216
|
+
| K_POP _ L_COLON _ K_ALL => ( { pop: "all" } )
|
|
217
|
+
| K_HIGHLIGHT _ L_COLON _ T_STRING => ( { highlight: $4 } )
|
|
218
|
+
| K_EMBED _ L_COLON _ T_STRING => ( { embed: $4 } )
|
|
219
|
+
| K_UNEMBED => ( { unembed: true } )
|
|
220
|
+
| K_INSET => ( { inset: 1 } )
|
|
221
|
+
| K_INSET _ L_COLON _ T_INTEGER => ( { inset: parseInt($4) } )
|
|
222
|
+
| K_SET _ L_COLON _ T_WORD => ( { set: $4 } )
|
|
223
|
+
| K_GOTO _ L_COLON _ T_WORD => ( { goto: $4 } )
|
|
224
|
+
| K_TYPE _ L_COLON _ T_STRING => ( { type: $4 } )
|
|
225
|
+
|
|
226
|
+
[grammar]
|
|
227
|
+
| kv_list _ grammar_rule_list => ( { config: Object.assign(...$0), rules: $2 } )
|
|
228
|
+
| grammar_rule_list => ( { rules: $0 } )
|
|
229
|
+
|
|
230
|
+
[grammar_rule_list]
|
|
231
|
+
| grammar_rule => ( [$0] )
|
|
232
|
+
| grammar_rule _ grammar_rule_list => ( [$0].concat($2) )
|
|
233
|
+
|
|
234
|
+
[grammar_rule]
|
|
235
|
+
| T_WORD _ L_ARROW _ expression_list => ( { name: $0, expressions: $4 } )
|
|
236
|
+
| T_WORD __ L_COLON _ T_JS@js _ L_ARROW _ expression_list@expressions => ( { name: $0, expressions: $expressions, postprocess: $js } )
|
|
237
|
+
| T_WORD __ L_COLON _ T_GRAMMAR_TEMPLATE@template _ L_ARROW _ expression_list@expressions => ( { name: $0, expressions: $expressions, postprocess: $template } )
|
|
238
|
+
|
|
239
|
+
[expression_list]
|
|
240
|
+
| expression
|
|
241
|
+
| expression_list _ L_PIPE _ expression => ( $0.concat([$4]) )
|
|
242
|
+
|
|
243
|
+
[expression]
|
|
244
|
+
| expression_symbol_list => ( { symbols: $0 } )
|
|
245
|
+
| expression_symbol_list __ L_COLON _ T_JS@js => ( { symbols: $0, postprocess: $js } )
|
|
246
|
+
| expression_symbol_list __ L_COLON _ T_GRAMMAR_TEMPLATE@template => ( { symbols: $0, postprocess: $template } )
|
|
247
|
+
|
|
248
|
+
[expression_symbol_list]
|
|
249
|
+
| expression_symbol
|
|
250
|
+
| expression_symbol_list T_WS expression_symbol => ( $0.concat([$2]) )
|
|
251
|
+
|
|
252
|
+
[expression_symbol]
|
|
253
|
+
| expression_symbol_match => ( $0 )
|
|
254
|
+
| expression_symbol_match L_COLON T_WORD => ( { ...$0, alias: $2 } )
|
|
255
|
+
| expression_symbol_match expression_repeater => ( { expression: $0, repeat: $1 } )
|
|
256
|
+
| expression_symbol_match expression_repeater L_COLON T_WORD => ( { expression: $0, repeat: $1, alias: $4 } )
|
|
257
|
+
|
|
258
|
+
[expression_symbol_match]
|
|
259
|
+
| T_WORD => ( { rule: $0 } )
|
|
260
|
+
| T_STRING "i"? => ( { literal: $0, insensitive: !!$1 } )
|
|
261
|
+
| L_DSIGN T_WORD => ( { token: $1} )
|
|
262
|
+
| L_DSIGN T_STRING => ( { token: $1} )
|
|
263
|
+
| T_REGEX => ( $0 )
|
|
264
|
+
| L_PARENL _ expression_list _ L_PARENR => ( { subexpression: $2 } )
|
|
265
|
+
| T_JS => ( $0 )
|
|
266
|
+
|
|
267
|
+
[expression_repeater] => ( $0[0].value )
|
|
268
|
+
| L_QMARK
|
|
269
|
+
| L_PLUS
|
|
270
|
+
| L_STAR
|
|
271
|
+
|
|
272
|
+
[kv_list]
|
|
273
|
+
| kv => ( data )
|
|
274
|
+
| kv _ kv_list => ( [$0].concat($2) )
|
|
275
|
+
|
|
276
|
+
[kv]
|
|
277
|
+
| T_WORD _ L_COLON _ (T_WORD | T_STRING | T_INTEGER | T_JS | T_GRAMMAR_TEMPLATE) => ( { [$0]: $4[0] } )
|
|
278
|
+
|
|
279
|
+
[string_list]
|
|
280
|
+
| T_STRING => ( [$0] )
|
|
281
|
+
| T_STRING _ L_COMMA _ string_list => ( [$0].concat($4) )
|
|
282
|
+
|
|
283
|
+
[word_list]
|
|
284
|
+
| T_WORD => ( [$0] )
|
|
285
|
+
| T_WORD _ L_COMMA _ word_list => ( [$0].concat($4) )
|
|
286
|
+
|
|
287
|
+
[_]
|
|
288
|
+
| (T_WS | T_COMMENT)* => ( null )
|
|
289
|
+
|
|
290
|
+
[__]
|
|
291
|
+
| (T_WS | T_COMMENT)+ => ( null )
|
|
292
|
+
|
|
293
|
+
[L_COLON]
|
|
294
|
+
| <L_COLON>
|
|
295
|
+
|
|
296
|
+
[L_SCOLON]
|
|
297
|
+
| <L_SCOLON>
|
|
298
|
+
|
|
299
|
+
[L_QMARK]
|
|
300
|
+
| <L_QMARK>
|
|
301
|
+
|
|
302
|
+
[L_PLUS]
|
|
303
|
+
| <L_PLUS>
|
|
304
|
+
|
|
305
|
+
[L_STAR]
|
|
306
|
+
| <L_STAR>
|
|
307
|
+
|
|
308
|
+
[L_COMMA]
|
|
309
|
+
| <L_COMMA>
|
|
310
|
+
|
|
311
|
+
[L_PIPE]
|
|
312
|
+
| <L_PIPE>
|
|
313
|
+
|
|
314
|
+
[L_PARENL]
|
|
315
|
+
| <L_PARENL>
|
|
316
|
+
|
|
317
|
+
[L_PARENR]
|
|
318
|
+
| <L_PARENR>
|
|
319
|
+
|
|
320
|
+
[L_TEMPLATEL]
|
|
321
|
+
| <L_TEMPLATEL>
|
|
322
|
+
|
|
323
|
+
[L_TEMPLATER]
|
|
324
|
+
| <L_TEMPLATER>
|
|
325
|
+
|
|
326
|
+
[L_ARROW]
|
|
327
|
+
| <L_ARROW>
|
|
328
|
+
|
|
329
|
+
[L_DSIGN]
|
|
330
|
+
| <L_DSIGN>
|
|
331
|
+
|
|
332
|
+
[L_DASH]
|
|
333
|
+
| <L_DASH>
|
|
334
|
+
|
|
335
|
+
[K_ALL]
|
|
336
|
+
| "all"
|
|
337
|
+
|
|
338
|
+
[K_TAG]
|
|
339
|
+
| "tag"
|
|
340
|
+
|
|
341
|
+
[K_FROM]
|
|
342
|
+
| "from"
|
|
343
|
+
|
|
344
|
+
[K_TYPE]
|
|
345
|
+
| "type"
|
|
346
|
+
|
|
347
|
+
[K_WHEN]
|
|
348
|
+
| "when"
|
|
349
|
+
|
|
350
|
+
[K_POP]
|
|
351
|
+
| "pop"
|
|
352
|
+
|
|
353
|
+
[K_BEFORE]
|
|
354
|
+
| "before"
|
|
355
|
+
|
|
356
|
+
[K_OPEN]
|
|
357
|
+
| "open"
|
|
358
|
+
|
|
359
|
+
[K_CLOSE]
|
|
360
|
+
| "close"
|
|
361
|
+
|
|
362
|
+
[K_HIGHLIGHT]
|
|
363
|
+
| "highlight"
|
|
364
|
+
|
|
365
|
+
[K_EMBED]
|
|
366
|
+
| "embed"
|
|
367
|
+
|
|
368
|
+
[K_UNEMBED]
|
|
369
|
+
| "unembed"
|
|
370
|
+
|
|
371
|
+
[K_INSET]
|
|
372
|
+
| "inset"
|
|
373
|
+
|
|
374
|
+
[K_SET]
|
|
375
|
+
| "set"
|
|
376
|
+
|
|
377
|
+
[K_GOTO]
|
|
378
|
+
| "goto"
|
|
379
|
+
|
|
380
|
+
[K_CONFIG]
|
|
381
|
+
| "config"
|
|
382
|
+
|
|
383
|
+
[K_LEXER]
|
|
384
|
+
| "lexer"
|
|
385
|
+
|
|
386
|
+
[K_GRAMMAR]
|
|
387
|
+
| "grammar"
|
|
388
|
+
|
|
389
|
+
[K_IMPORT]
|
|
390
|
+
| "import"
|
|
391
|
+
|
|
392
|
+
[K_BODY]
|
|
393
|
+
| "body"
|
|
394
|
+
|
|
395
|
+
[K_HEAD]
|
|
396
|
+
| "head"
|
|
397
|
+
|
|
398
|
+
[T_JS]
|
|
399
|
+
| <L_JSL> <T_JSBODY>* <L_JSR> => ( { js: $1.map(v=>v.value).join('') } )
|
|
400
|
+
|
|
401
|
+
[T_GRAMMAR_TEMPLATE]
|
|
402
|
+
| <L_TEMPLATEL> _ <T_JSBODY>* _ <L_TEMPLATER> => ( { template: '(' + $2.map(v=>v.value).join('').trim() + ')' } )
|
|
403
|
+
|
|
404
|
+
[T_STRING]
|
|
405
|
+
| <T_STRING> => ( JSON.parse($0.value) )
|
|
406
|
+
|
|
407
|
+
[T_WORD]
|
|
408
|
+
| <T_WORD> => ( $0.value )
|
|
409
|
+
|
|
410
|
+
[T_REGEX]
|
|
411
|
+
| <T_REGEX> r:{[gmiuy]}* => ( { regex: $0.value.slice(1,-1), flags: $1.map(v=>v.value).join('').trim() } )
|
|
412
|
+
|
|
413
|
+
[T_COMMENT]
|
|
414
|
+
| <T_COMMENT>
|
|
415
|
+
|
|
416
|
+
[T_INTEGER]
|
|
417
|
+
| <T_INTEGER> => ( $0.value )
|
|
418
|
+
|
|
419
|
+
[T_WS]
|
|
420
|
+
| <T_WS> => ( null )
|
|
421
|
+
|
|
422
|
+
}
|