grammar-well 1.1.2 → 1.1.4
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/build/compiler/compiler.d.ts +49 -49
- package/build/compiler/compiler.js +227 -227
- package/build/compiler/generator.d.ts +23 -23
- package/build/compiler/generator.js +213 -212
- package/build/compiler/generator.js.map +1 -1
- package/build/compiler/import-resolver.d.ts +15 -15
- package/build/compiler/import-resolver.js +36 -36
- package/build/compiler/outputs/javascript.d.ts +3 -3
- package/build/compiler/outputs/javascript.js +14 -14
- package/build/compiler/outputs/json.d.ts +2 -2
- package/build/compiler/outputs/json.js +7 -7
- package/build/compiler/outputs/typescript.d.ts +2 -2
- package/build/compiler/outputs/typescript.js +9 -8
- package/build/compiler/outputs/typescript.js.map +1 -1
- package/build/grammars/gwell.d.ts +1023 -997
- package/build/grammars/gwell.js +540 -536
- package/build/grammars/gwell.js.map +1 -1
- package/build/grammars/json.d.ts +151 -151
- package/build/grammars/json.js +111 -111
- package/build/grammars/number.d.ts +239 -239
- package/build/grammars/number.js +114 -114
- package/build/grammars/number.json +1 -1
- package/build/grammars/string.d.ts +116 -116
- package/build/grammars/string.js +49 -49
- package/build/grammars/string.json +1 -1
- package/build/grammars/whitespace.d.ts +51 -51
- package/build/grammars/whitespace.js +29 -29
- package/build/grammars/whitespace.json +1 -1
- package/build/index.d.ts +4 -4
- package/build/index.js +20 -20
- package/build/lexers/character-lexer.d.ts +27 -27
- package/build/lexers/character-lexer.js +70 -70
- package/build/lexers/stateful-lexer.d.ts +48 -48
- package/build/lexers/stateful-lexer.js +308 -308
- package/build/lexers/token-buffer.d.ts +32 -32
- package/build/lexers/token-buffer.js +91 -91
- package/build/parser/algorithms/cyk.d.ts +16 -16
- package/build/parser/algorithms/cyk.js +57 -57
- package/build/parser/algorithms/earley.d.ts +48 -48
- package/build/parser/algorithms/earley.js +157 -157
- package/build/parser/algorithms/lr.d.ts +10 -10
- package/build/parser/algorithms/lr.js +33 -33
- package/build/parser/parser.d.ts +26 -26
- package/build/parser/parser.js +73 -73
- package/build/typings.d.ts +199 -198
- package/build/typings.js +2 -2
- package/build/utility/general.d.ts +55 -55
- package/build/utility/general.js +175 -165
- package/build/utility/general.js.map +1 -1
- package/build/utility/lint.d.ts +2 -2
- package/build/utility/lint.js +27 -27
- package/build/utility/lr.d.ts +52 -52
- package/build/utility/lr.js +129 -129
- package/build/utility/text-format.d.ts +11 -11
- package/build/utility/text-format.js +83 -83
- package/package.json +1 -1
- package/src/compiler/generator.ts +1 -0
- package/src/compiler/outputs/typescript.ts +2 -1
- package/src/grammars/gwell.gwell +15 -13
- package/src/grammars/gwell.js +17 -13
- package/src/grammars/gwell.json +1 -1
- package/src/typings.ts +1 -0
- package/src/utility/general.ts +31 -19
package/build/utility/general.js
CHANGED
|
@@ -1,166 +1,176 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Unflatten = exports.Flatten = exports.Matrix = exports.SymbolCollection = exports.Collection = void 0;
|
|
4
|
-
class Collection {
|
|
5
|
-
categorized = {};
|
|
6
|
-
uncategorized = new Map();
|
|
7
|
-
items = [];
|
|
8
|
-
constructor(ref = []) {
|
|
9
|
-
for (const s of ref) {
|
|
10
|
-
this.encode(s);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
encode(ref) {
|
|
14
|
-
const c = this.resolve(ref);
|
|
15
|
-
if (c)
|
|
16
|
-
return this.addCategorized(c.category, c.key, ref);
|
|
17
|
-
return this.addUncategorized(ref);
|
|
18
|
-
}
|
|
19
|
-
decode(id) {
|
|
20
|
-
return this.items[typeof id == 'string' ? parseInt(id) : id];
|
|
21
|
-
}
|
|
22
|
-
has(ref) {
|
|
23
|
-
const c = this.resolve(ref);
|
|
24
|
-
if (c)
|
|
25
|
-
return (c.key in this.categorized[c.category]);
|
|
26
|
-
return this.uncategorized.has(ref);
|
|
27
|
-
}
|
|
28
|
-
redirect(source, target) {
|
|
29
|
-
this.items[this.encode(source)] = target;
|
|
30
|
-
}
|
|
31
|
-
resolve(_) { }
|
|
32
|
-
addCategorized(category, key, ref) {
|
|
33
|
-
if (!(key in this.categorized[category])) {
|
|
34
|
-
this.categorized[category][key] = this.items.length;
|
|
35
|
-
this.items.push(ref);
|
|
36
|
-
}
|
|
37
|
-
return this.categorized[category][key];
|
|
38
|
-
}
|
|
39
|
-
addUncategorized(ref) {
|
|
40
|
-
if (!this.uncategorized.has(ref)) {
|
|
41
|
-
this.uncategorized.set(ref, this.items.length);
|
|
42
|
-
this.items.push(ref);
|
|
43
|
-
}
|
|
44
|
-
return this.uncategorized.get(ref);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
exports.Collection = Collection;
|
|
48
|
-
class SymbolCollection extends Collection {
|
|
49
|
-
categorized = {
|
|
50
|
-
nonTerminal: {},
|
|
51
|
-
literalI: {},
|
|
52
|
-
literalS: {},
|
|
53
|
-
token: {},
|
|
54
|
-
regex: {},
|
|
55
|
-
function: {},
|
|
56
|
-
};
|
|
57
|
-
resolve(symbol) {
|
|
58
|
-
if (typeof symbol == 'string') {
|
|
59
|
-
return { category: 'nonTerminal', key: symbol };
|
|
60
|
-
}
|
|
61
|
-
else if ('literal' in symbol) {
|
|
62
|
-
if (symbol.insensitive)
|
|
63
|
-
return { category: 'literalI', key: symbol.literal };
|
|
64
|
-
return { category: 'literalS', key: symbol.literal };
|
|
65
|
-
}
|
|
66
|
-
else if ('token' in symbol) {
|
|
67
|
-
return { category: 'token', key: symbol.token };
|
|
68
|
-
}
|
|
69
|
-
else if (symbol instanceof RegExp) {
|
|
70
|
-
return { category: 'regex', key: symbol.toString() };
|
|
71
|
-
}
|
|
72
|
-
else if (typeof symbol == 'function') {
|
|
73
|
-
return { category: 'function', key: symbol.toString() };
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
exports.SymbolCollection = SymbolCollection;
|
|
78
|
-
class Matrix {
|
|
79
|
-
initial;
|
|
80
|
-
$x = 0;
|
|
81
|
-
$y = 0;
|
|
82
|
-
get x() { return this.$x; }
|
|
83
|
-
set x(x) { x != this.$x && this.resize(x, this.y); }
|
|
84
|
-
get y() { return this.$y; }
|
|
85
|
-
set y(y) { y != this.$y && this.resize(this.x, y); }
|
|
86
|
-
matrix = [];
|
|
87
|
-
constructor(x, y, initial) {
|
|
88
|
-
this.initial = initial;
|
|
89
|
-
this.resize(x, y);
|
|
90
|
-
}
|
|
91
|
-
get(x, y) {
|
|
92
|
-
return this.matrix[x][y];
|
|
93
|
-
}
|
|
94
|
-
set(x, y, value) {
|
|
95
|
-
return this.matrix[x][y] = value;
|
|
96
|
-
}
|
|
97
|
-
resize(x, y) {
|
|
98
|
-
if (x < this.x) {
|
|
99
|
-
this.matrix.splice(x);
|
|
100
|
-
this.$x = x;
|
|
101
|
-
}
|
|
102
|
-
if (y > this.y) {
|
|
103
|
-
this.matrix.forEach(a => a.push(...Matrix.Array(y - a.length, this.initial)));
|
|
104
|
-
this.$y = y;
|
|
105
|
-
}
|
|
106
|
-
else if (y < this.y) {
|
|
107
|
-
this.matrix.forEach(a => a.splice(y + 1));
|
|
108
|
-
this.$y = y;
|
|
109
|
-
}
|
|
110
|
-
if (x > this.x) {
|
|
111
|
-
const ext = Matrix.Array(x - this.x, () => Matrix.Array(this.y, this.initial));
|
|
112
|
-
this.matrix.push(...ext);
|
|
113
|
-
this.$x = x;
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
static Array(length, initial) {
|
|
117
|
-
return Array.from({ length }, (typeof initial == 'function' ? initial : () => initial));
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.Matrix = Matrix;
|
|
121
|
-
function Flatten(obj) {
|
|
122
|
-
const collection = new Collection();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
}
|
|
165
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Unflatten = exports.Flatten = exports.Matrix = exports.SymbolCollection = exports.Collection = void 0;
|
|
4
|
+
class Collection {
|
|
5
|
+
categorized = {};
|
|
6
|
+
uncategorized = new Map();
|
|
7
|
+
items = [];
|
|
8
|
+
constructor(ref = []) {
|
|
9
|
+
for (const s of ref) {
|
|
10
|
+
this.encode(s);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
encode(ref) {
|
|
14
|
+
const c = this.resolve(ref);
|
|
15
|
+
if (c)
|
|
16
|
+
return this.addCategorized(c.category, c.key, ref);
|
|
17
|
+
return this.addUncategorized(ref);
|
|
18
|
+
}
|
|
19
|
+
decode(id) {
|
|
20
|
+
return this.items[typeof id == 'string' ? parseInt(id) : id];
|
|
21
|
+
}
|
|
22
|
+
has(ref) {
|
|
23
|
+
const c = this.resolve(ref);
|
|
24
|
+
if (c)
|
|
25
|
+
return (c.key in this.categorized[c.category]);
|
|
26
|
+
return this.uncategorized.has(ref);
|
|
27
|
+
}
|
|
28
|
+
redirect(source, target) {
|
|
29
|
+
this.items[this.encode(source)] = target;
|
|
30
|
+
}
|
|
31
|
+
resolve(_) { }
|
|
32
|
+
addCategorized(category, key, ref) {
|
|
33
|
+
if (!(key in this.categorized[category])) {
|
|
34
|
+
this.categorized[category][key] = this.items.length;
|
|
35
|
+
this.items.push(ref);
|
|
36
|
+
}
|
|
37
|
+
return this.categorized[category][key];
|
|
38
|
+
}
|
|
39
|
+
addUncategorized(ref) {
|
|
40
|
+
if (!this.uncategorized.has(ref)) {
|
|
41
|
+
this.uncategorized.set(ref, this.items.length);
|
|
42
|
+
this.items.push(ref);
|
|
43
|
+
}
|
|
44
|
+
return this.uncategorized.get(ref);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.Collection = Collection;
|
|
48
|
+
class SymbolCollection extends Collection {
|
|
49
|
+
categorized = {
|
|
50
|
+
nonTerminal: {},
|
|
51
|
+
literalI: {},
|
|
52
|
+
literalS: {},
|
|
53
|
+
token: {},
|
|
54
|
+
regex: {},
|
|
55
|
+
function: {},
|
|
56
|
+
};
|
|
57
|
+
resolve(symbol) {
|
|
58
|
+
if (typeof symbol == 'string') {
|
|
59
|
+
return { category: 'nonTerminal', key: symbol };
|
|
60
|
+
}
|
|
61
|
+
else if ('literal' in symbol) {
|
|
62
|
+
if (symbol.insensitive)
|
|
63
|
+
return { category: 'literalI', key: symbol.literal };
|
|
64
|
+
return { category: 'literalS', key: symbol.literal };
|
|
65
|
+
}
|
|
66
|
+
else if ('token' in symbol) {
|
|
67
|
+
return { category: 'token', key: symbol.token };
|
|
68
|
+
}
|
|
69
|
+
else if (symbol instanceof RegExp) {
|
|
70
|
+
return { category: 'regex', key: symbol.toString() };
|
|
71
|
+
}
|
|
72
|
+
else if (typeof symbol == 'function') {
|
|
73
|
+
return { category: 'function', key: symbol.toString() };
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
exports.SymbolCollection = SymbolCollection;
|
|
78
|
+
class Matrix {
|
|
79
|
+
initial;
|
|
80
|
+
$x = 0;
|
|
81
|
+
$y = 0;
|
|
82
|
+
get x() { return this.$x; }
|
|
83
|
+
set x(x) { x != this.$x && this.resize(x, this.y); }
|
|
84
|
+
get y() { return this.$y; }
|
|
85
|
+
set y(y) { y != this.$y && this.resize(this.x, y); }
|
|
86
|
+
matrix = [];
|
|
87
|
+
constructor(x, y, initial) {
|
|
88
|
+
this.initial = initial;
|
|
89
|
+
this.resize(x, y);
|
|
90
|
+
}
|
|
91
|
+
get(x, y) {
|
|
92
|
+
return this.matrix[x][y];
|
|
93
|
+
}
|
|
94
|
+
set(x, y, value) {
|
|
95
|
+
return this.matrix[x][y] = value;
|
|
96
|
+
}
|
|
97
|
+
resize(x, y) {
|
|
98
|
+
if (x < this.x) {
|
|
99
|
+
this.matrix.splice(x);
|
|
100
|
+
this.$x = x;
|
|
101
|
+
}
|
|
102
|
+
if (y > this.y) {
|
|
103
|
+
this.matrix.forEach(a => a.push(...Matrix.Array(y - a.length, this.initial)));
|
|
104
|
+
this.$y = y;
|
|
105
|
+
}
|
|
106
|
+
else if (y < this.y) {
|
|
107
|
+
this.matrix.forEach(a => a.splice(y + 1));
|
|
108
|
+
this.$y = y;
|
|
109
|
+
}
|
|
110
|
+
if (x > this.x) {
|
|
111
|
+
const ext = Matrix.Array(x - this.x, () => Matrix.Array(this.y, this.initial));
|
|
112
|
+
this.matrix.push(...ext);
|
|
113
|
+
this.$x = x;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
static Array(length, initial) {
|
|
117
|
+
return Array.from({ length }, (typeof initial == 'function' ? initial : () => initial));
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
exports.Matrix = Matrix;
|
|
121
|
+
function Flatten(obj) {
|
|
122
|
+
const collection = new Collection();
|
|
123
|
+
const $null = Symbol();
|
|
124
|
+
function Traverse(src) {
|
|
125
|
+
if (src == null) {
|
|
126
|
+
src = $null;
|
|
127
|
+
}
|
|
128
|
+
if (collection.has(src)) {
|
|
129
|
+
return collection.encode(src);
|
|
130
|
+
}
|
|
131
|
+
collection.encode(src);
|
|
132
|
+
if (Array.isArray(src)) {
|
|
133
|
+
collection.redirect(src, src.map(v => Traverse(v)));
|
|
134
|
+
}
|
|
135
|
+
else if (typeof src === 'object') {
|
|
136
|
+
const o = {};
|
|
137
|
+
for (const k in src) {
|
|
138
|
+
o[k] = Traverse(src[k]);
|
|
139
|
+
}
|
|
140
|
+
collection.redirect(src, o);
|
|
141
|
+
}
|
|
142
|
+
else if (typeof src === 'function') {
|
|
143
|
+
return collection.redirect(src, src.toString());
|
|
144
|
+
}
|
|
145
|
+
return collection.encode(src);
|
|
146
|
+
}
|
|
147
|
+
Traverse(obj);
|
|
148
|
+
collection.redirect($null, null);
|
|
149
|
+
return collection.items;
|
|
150
|
+
}
|
|
151
|
+
exports.Flatten = Flatten;
|
|
152
|
+
function Unflatten(items) {
|
|
153
|
+
const visited = new Set();
|
|
154
|
+
function Traverse(id) {
|
|
155
|
+
if (visited.has(id)) {
|
|
156
|
+
return items[id];
|
|
157
|
+
}
|
|
158
|
+
visited.add(id);
|
|
159
|
+
const obj = items[id];
|
|
160
|
+
if (Array.isArray(obj)) {
|
|
161
|
+
for (let i = 0; i < obj.length; i++) {
|
|
162
|
+
const ii = obj[i];
|
|
163
|
+
obj[i] = Traverse(ii);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else if (typeof obj === 'object') {
|
|
167
|
+
for (const k in obj) {
|
|
168
|
+
obj[k] = Traverse(obj[k]);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return obj;
|
|
172
|
+
}
|
|
173
|
+
return Traverse(0);
|
|
174
|
+
}
|
|
175
|
+
exports.Unflatten = Unflatten;
|
|
166
176
|
//# sourceMappingURL=general.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general.js","sourceRoot":"","sources":["../../src/utility/general.ts"],"names":[],"mappings":";;;AAGA,MAAa,UAAU;IACnB,WAAW,GAAmC,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"general.js","sourceRoot":"","sources":["../../src/utility/general.ts"],"names":[],"mappings":";;;AAGA,MAAa,UAAU;IACnB,WAAW,GAAmC,E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1
|
-
import { LanguageDefinition, GrammarRuleSymbol } from "../typings";
|
|
2
|
-
export declare function LintGrammarSymbols(language: LanguageDefinition): GrammarRuleSymbol[];
|
|
1
|
+
import { LanguageDefinition, GrammarRuleSymbol } from "../typings";
|
|
2
|
+
export declare function LintGrammarSymbols(language: LanguageDefinition): GrammarRuleSymbol[];
|
package/build/utility/lint.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LintGrammarSymbols = void 0;
|
|
4
|
-
function LintGrammarSymbols(language) {
|
|
5
|
-
const unused = new Set();
|
|
6
|
-
const { rules, start } = language.grammar;
|
|
7
|
-
for (const rule in rules) {
|
|
8
|
-
unused.add(rule);
|
|
9
|
-
}
|
|
10
|
-
TraverseRule(start, rules, unused);
|
|
11
|
-
return Array.from(unused);
|
|
12
|
-
}
|
|
13
|
-
exports.LintGrammarSymbols = LintGrammarSymbols;
|
|
14
|
-
function TraverseRule(name, rules, unvisited) {
|
|
15
|
-
if (!unvisited.has(name)) {
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
unvisited.add(name);
|
|
19
|
-
const n = rules[name];
|
|
20
|
-
for (const { symbols } of n) {
|
|
21
|
-
for (const symbol of symbols) {
|
|
22
|
-
if (typeof symbol == 'string') {
|
|
23
|
-
TraverseRule(symbol, rules, unvisited);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LintGrammarSymbols = void 0;
|
|
4
|
+
function LintGrammarSymbols(language) {
|
|
5
|
+
const unused = new Set();
|
|
6
|
+
const { rules, start } = language.grammar;
|
|
7
|
+
for (const rule in rules) {
|
|
8
|
+
unused.add(rule);
|
|
9
|
+
}
|
|
10
|
+
TraverseRule(start, rules, unused);
|
|
11
|
+
return Array.from(unused);
|
|
12
|
+
}
|
|
13
|
+
exports.LintGrammarSymbols = LintGrammarSymbols;
|
|
14
|
+
function TraverseRule(name, rules, unvisited) {
|
|
15
|
+
if (!unvisited.has(name)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
unvisited.add(name);
|
|
19
|
+
const n = rules[name];
|
|
20
|
+
for (const { symbols } of n) {
|
|
21
|
+
for (const symbol of symbols) {
|
|
22
|
+
if (typeof symbol == 'string') {
|
|
23
|
+
TraverseRule(symbol, rules, unvisited);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
28
|
//# sourceMappingURL=lint.js.map
|
package/build/utility/lr.d.ts
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
import { Dictionary, GrammarRule, GrammarRuleSymbol, LanguageDefinition } from "../typings";
|
|
2
|
-
import { Collection, SymbolCollection } from "./general";
|
|
3
|
-
export declare class CanonicalCollection {
|
|
4
|
-
grammar: LanguageGrammar;
|
|
5
|
-
rules: Collection<GrammarRule>;
|
|
6
|
-
states: {
|
|
7
|
-
[key: string]: State;
|
|
8
|
-
};
|
|
9
|
-
symbols: SymbolCollection;
|
|
10
|
-
constructor(grammar: LanguageGrammar);
|
|
11
|
-
addState(seed: StateItem[]): State;
|
|
12
|
-
encodeRule(rule: GrammarRule, dot: number): string;
|
|
13
|
-
encodeStateItems(seed: StateItem[]): string;
|
|
14
|
-
}
|
|
15
|
-
declare class State {
|
|
16
|
-
private collection;
|
|
17
|
-
isFinal: boolean;
|
|
18
|
-
outputs: StateOut;
|
|
19
|
-
queue: {
|
|
20
|
-
[key: string]: StateItem[];
|
|
21
|
-
};
|
|
22
|
-
actions: Map<GrammarRuleSymbol, string>;
|
|
23
|
-
goto: Map<GrammarRuleSymbol, string>;
|
|
24
|
-
reduce?: GrammarRule;
|
|
25
|
-
constructor(collection: CanonicalCollection, items: StateItem[]);
|
|
26
|
-
private closure;
|
|
27
|
-
}
|
|
28
|
-
export declare class LRStack {
|
|
29
|
-
stack: LRStackItem[];
|
|
30
|
-
get current(): LRStackItem;
|
|
31
|
-
get previous(): LRStackItem;
|
|
32
|
-
shift(state: State): void;
|
|
33
|
-
reduce(rule: GrammarRule): void;
|
|
34
|
-
add(symbol: GrammarRuleSymbol): void;
|
|
35
|
-
}
|
|
36
|
-
declare class LRStackItem {
|
|
37
|
-
children: LRStackItem[];
|
|
38
|
-
state: State;
|
|
39
|
-
symbol: GrammarRuleSymbol;
|
|
40
|
-
rule: GrammarRule;
|
|
41
|
-
value: any;
|
|
42
|
-
}
|
|
43
|
-
type LanguageGrammar = LanguageDefinition['grammar'];
|
|
44
|
-
type StateItem = {
|
|
45
|
-
rule: GrammarRule;
|
|
46
|
-
dot: number;
|
|
47
|
-
};
|
|
48
|
-
interface StateOut {
|
|
49
|
-
action: Dictionary<StateItem[]>;
|
|
50
|
-
goto: Dictionary<StateItem[]>;
|
|
51
|
-
}
|
|
52
|
-
export {};
|
|
1
|
+
import { Dictionary, GrammarRule, GrammarRuleSymbol, LanguageDefinition } from "../typings";
|
|
2
|
+
import { Collection, SymbolCollection } from "./general";
|
|
3
|
+
export declare class CanonicalCollection {
|
|
4
|
+
grammar: LanguageGrammar;
|
|
5
|
+
rules: Collection<GrammarRule>;
|
|
6
|
+
states: {
|
|
7
|
+
[key: string]: State;
|
|
8
|
+
};
|
|
9
|
+
symbols: SymbolCollection;
|
|
10
|
+
constructor(grammar: LanguageGrammar);
|
|
11
|
+
addState(seed: StateItem[]): State;
|
|
12
|
+
encodeRule(rule: GrammarRule, dot: number): string;
|
|
13
|
+
encodeStateItems(seed: StateItem[]): string;
|
|
14
|
+
}
|
|
15
|
+
declare class State {
|
|
16
|
+
private collection;
|
|
17
|
+
isFinal: boolean;
|
|
18
|
+
outputs: StateOut;
|
|
19
|
+
queue: {
|
|
20
|
+
[key: string]: StateItem[];
|
|
21
|
+
};
|
|
22
|
+
actions: Map<GrammarRuleSymbol, string>;
|
|
23
|
+
goto: Map<GrammarRuleSymbol, string>;
|
|
24
|
+
reduce?: GrammarRule;
|
|
25
|
+
constructor(collection: CanonicalCollection, items: StateItem[]);
|
|
26
|
+
private closure;
|
|
27
|
+
}
|
|
28
|
+
export declare class LRStack {
|
|
29
|
+
stack: LRStackItem[];
|
|
30
|
+
get current(): LRStackItem;
|
|
31
|
+
get previous(): LRStackItem;
|
|
32
|
+
shift(state: State): void;
|
|
33
|
+
reduce(rule: GrammarRule): void;
|
|
34
|
+
add(symbol: GrammarRuleSymbol): void;
|
|
35
|
+
}
|
|
36
|
+
declare class LRStackItem {
|
|
37
|
+
children: LRStackItem[];
|
|
38
|
+
state: State;
|
|
39
|
+
symbol: GrammarRuleSymbol;
|
|
40
|
+
rule: GrammarRule;
|
|
41
|
+
value: any;
|
|
42
|
+
}
|
|
43
|
+
type LanguageGrammar = LanguageDefinition['grammar'];
|
|
44
|
+
type StateItem = {
|
|
45
|
+
rule: GrammarRule;
|
|
46
|
+
dot: number;
|
|
47
|
+
};
|
|
48
|
+
interface StateOut {
|
|
49
|
+
action: Dictionary<StateItem[]>;
|
|
50
|
+
goto: Dictionary<StateItem[]>;
|
|
51
|
+
}
|
|
52
|
+
export {};
|