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,20 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const { states, rules: rules } = new canonical_collection_1.CanonicalCollection(grammar);
|
|
10
|
-
const stack = new stack_1.LRStack();
|
|
1
|
+
import { ParserUtility } from "../../../utility/parsing.js";
|
|
2
|
+
import { CanonicalCollection } from "./canonical-collection.js";
|
|
3
|
+
import { LRStack } from "./stack.js";
|
|
4
|
+
export function LRK(language, options = {}) {
|
|
5
|
+
const { grammar } = language.artifacts;
|
|
6
|
+
const { tokens } = language;
|
|
7
|
+
const { states, rules: rules } = new CanonicalCollection(grammar);
|
|
8
|
+
const stack = new LRStack();
|
|
11
9
|
const s = states.get('0.0');
|
|
12
10
|
stack.append(s.rule.name);
|
|
13
11
|
stack.shift(s);
|
|
14
12
|
let token;
|
|
15
13
|
while (token = tokens.next()) {
|
|
16
14
|
for (const [symbol, state] of stack.current.state.actions) {
|
|
17
|
-
if (
|
|
15
|
+
if (ParserUtility.SymbolMatchesToken(symbol, token)) {
|
|
18
16
|
stack.append(symbol);
|
|
19
17
|
stack.shift(states.get(state));
|
|
20
18
|
stack.current.value = token;
|
|
@@ -24,12 +22,11 @@ function LRK(language, options = {}) {
|
|
|
24
22
|
while (stack.current.state?.isFinal) {
|
|
25
23
|
const rule = rules.fetch(stack.current.state.reduce);
|
|
26
24
|
stack.reduce(rule);
|
|
27
|
-
stack.current.value =
|
|
25
|
+
stack.current.value = ParserUtility.PostProcess(rule, stack.current.children.map(v => v.value));
|
|
28
26
|
const s = stack.previous.state.goto.get(rule.name);
|
|
29
27
|
stack.shift(states.get(s));
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
return { results: [stack.current.value] };
|
|
33
31
|
}
|
|
34
|
-
exports.LRK = LRK;
|
|
35
32
|
//# sourceMappingURL=algorithm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"algorithm.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/algorithm.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"algorithm.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/algorithm.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,UAAU,GAAG,CAAC,QAAsD,EAAE,OAAO,GAAG,EAAE;IACpF,MAAM,EAAE,OAAO,EAAE,GAAG,QAAQ,CAAC,SAAS,CAAC;IACvC,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAAC;IAC5B,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,IAAI,mBAAmB,CAAC,OAAO,CAAC,CAAC;IAClE,MAAM,KAAK,GAAG,IAAI,OAAO,EAAE,CAAC;IAC5B,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC5B,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACf,IAAI,KAAK,CAAC;IAEV,OAAO,KAAK,GAAG,MAAM,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3B,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;YACxD,IAAI,aAAa,CAAC,kBAAkB,CAAC,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC;gBAClD,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;gBACrB,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC/B,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;gBAC5B,MAAM;YACV,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,EAAE,CAAC;YAClC,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACrD,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YACnB,KAAK,CAAC,OAAO,CAAC,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;YAChG,MAAM,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnD,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAE/B,CAAC;IACL,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAA;AAC7C,CAAC"}
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BiMap = void 0;
|
|
4
|
-
class BiMap {
|
|
1
|
+
export class BiMap {
|
|
5
2
|
map = new Map();
|
|
6
3
|
items = [];
|
|
7
4
|
id(ref) {
|
|
@@ -15,5 +12,4 @@ class BiMap {
|
|
|
15
12
|
return this.items[index];
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.BiMap = BiMap;
|
|
19
15
|
//# sourceMappingURL=bimap.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bimap.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/bimap.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bimap.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/bimap.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;IACN,GAAG,GAAmB,IAAI,GAAG,EAAE,CAAC;IAChC,KAAK,GAAQ,EAAE,CAAC;IAExB,EAAE,CAAC,GAAM;QACL,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACrC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;QAED,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,KAAK,CAAC,KAAa;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAC7B,CAAC;CACJ"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BiMap } from "./bimap";
|
|
3
|
-
import { State } from "./state";
|
|
1
|
+
import { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeParserClass } from "../../../typings/index.js";
|
|
2
|
+
import { BiMap } from "./bimap.js";
|
|
3
|
+
import { State } from "./state.js";
|
|
4
4
|
export declare class CanonicalCollection {
|
|
5
|
-
grammar:
|
|
5
|
+
grammar: RuntimeParserClass['artifacts']['grammar'];
|
|
6
6
|
states: Map<string, State>;
|
|
7
|
-
rules: BiMap<
|
|
8
|
-
terminals: BiMap<
|
|
7
|
+
rules: BiMap<RuntimeGrammarProductionRule>;
|
|
8
|
+
terminals: BiMap<RuntimeGrammarRuleSymbol>;
|
|
9
9
|
private closure;
|
|
10
|
-
constructor(grammar:
|
|
10
|
+
constructor(grammar: RuntimeParserClass['artifacts']['grammar']);
|
|
11
11
|
private addState;
|
|
12
12
|
private linkStates;
|
|
13
13
|
private getStateId;
|
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const bimap_1 = require("./bimap");
|
|
6
|
-
const closure_1 = require("./closure");
|
|
7
|
-
class CanonicalCollection {
|
|
1
|
+
import { ParserUtility } from "../../../utility/parsing.js";
|
|
2
|
+
import { BiMap } from "./bimap.js";
|
|
3
|
+
import { ClosureBuilder } from "./closure.js";
|
|
4
|
+
export class CanonicalCollection {
|
|
8
5
|
grammar;
|
|
9
6
|
states = new Map();
|
|
10
|
-
rules = new
|
|
11
|
-
terminals = new
|
|
7
|
+
rules = new BiMap();
|
|
8
|
+
terminals = new BiMap();
|
|
12
9
|
closure;
|
|
13
10
|
constructor(grammar) {
|
|
14
11
|
this.grammar = grammar;
|
|
15
12
|
const augmented = {
|
|
16
13
|
name: Symbol(),
|
|
17
|
-
symbols: [grammar.start]
|
|
14
|
+
symbols: [this.grammar.start]
|
|
18
15
|
};
|
|
19
|
-
grammar['rules'][augmented.name] = [augmented];
|
|
20
|
-
this.closure = new
|
|
16
|
+
this.grammar['rules'][augmented.name] = [augmented];
|
|
17
|
+
this.closure = new ClosureBuilder(this.grammar);
|
|
21
18
|
this.rules.id(augmented);
|
|
22
|
-
this.addState(grammar['rules'][augmented.name][0], 0);
|
|
19
|
+
this.addState(this.grammar['rules'][augmented.name][0], 0);
|
|
23
20
|
this.linkStates('0.0');
|
|
24
21
|
}
|
|
25
22
|
addState(rule, dot) {
|
|
@@ -51,7 +48,7 @@ class CanonicalCollection {
|
|
|
51
48
|
for (const { rule, dot } of state.items) {
|
|
52
49
|
const symbol = rule.symbols[dot];
|
|
53
50
|
const itemStateId = this.getStateId(rule, dot + 1);
|
|
54
|
-
if (
|
|
51
|
+
if (ParserUtility.SymbolIsTerminal(symbol) && typeof symbol != 'symbol') {
|
|
55
52
|
state.actions.set(symbol, itemStateId);
|
|
56
53
|
}
|
|
57
54
|
else {
|
|
@@ -69,5 +66,4 @@ class CanonicalCollection {
|
|
|
69
66
|
return this.rules.id(rule) + '.' + dot;
|
|
70
67
|
}
|
|
71
68
|
}
|
|
72
|
-
exports.CanonicalCollection = CanonicalCollection;
|
|
73
69
|
//# sourceMappingURL=canonical-collection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical-collection.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/canonical-collection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"canonical-collection.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/canonical-collection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAG9C,MAAM,OAAO,mBAAmB;IAOjB;IANX,MAAM,GAAuB,IAAI,GAAG,EAAE,CAAC;IACvC,KAAK,GAAwC,IAAI,KAAK,EAAE,CAAC;IACzD,SAAS,GAAoC,IAAI,KAAK,EAAE,CAAC;IAEjD,OAAO,CAAiB;IAChC,YACW,OAAoD;QAApD,YAAO,GAAP,OAAO,CAA6C;QAE3D,MAAM,SAAS,GAAG;YACd,IAAI,EAAE,MAAM,EAAuB;YACnC,OAAO,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC;SAChC,CAAA;QACD,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChD,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;QACzB,IAAI,CAAC,QAA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|
2
2
|
export declare class ClosureBuilder {
|
|
3
3
|
private grammar;
|
|
4
|
-
constructor(grammar:
|
|
4
|
+
constructor(grammar: RuntimeParserClass['artifacts']['grammar']);
|
|
5
5
|
get(rule: string): {
|
|
6
|
-
rule:
|
|
6
|
+
rule: RuntimeGrammarProductionRule;
|
|
7
7
|
dot: number;
|
|
8
8
|
}[];
|
|
9
9
|
private addClosure;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.ClosureBuilder = void 0;
|
|
4
|
-
const parser_1 = require("../../parser");
|
|
5
|
-
class ClosureBuilder {
|
|
1
|
+
import { ParserUtility } from "../../../utility/parsing.js";
|
|
2
|
+
export class ClosureBuilder {
|
|
6
3
|
grammar;
|
|
7
4
|
constructor(grammar) {
|
|
8
5
|
this.grammar = grammar;
|
|
@@ -13,7 +10,7 @@ class ClosureBuilder {
|
|
|
13
10
|
return closure.items;
|
|
14
11
|
}
|
|
15
12
|
addClosure(closure, symbol) {
|
|
16
|
-
if (!
|
|
13
|
+
if (!ParserUtility.SymbolIsTerminal(symbol)) {
|
|
17
14
|
const key = symbol;
|
|
18
15
|
if (!(closure.visited.has(key))) {
|
|
19
16
|
closure.visited.add(key);
|
|
@@ -26,5 +23,4 @@ class ClosureBuilder {
|
|
|
26
23
|
}
|
|
27
24
|
}
|
|
28
25
|
}
|
|
29
|
-
exports.ClosureBuilder = ClosureBuilder;
|
|
30
26
|
//# sourceMappingURL=closure.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"closure.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/closure.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"closure.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/closure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,MAAM,OAAO,cAAc;IAEX;IADZ,YACY,OAAmD;QAAnD,YAAO,GAAP,OAAO,CAA4C;IAC3D,CAAC;IAEL,GAAG,CAAC,IAAY;QACZ,MAAM,OAAO,GAAgB,EAAE,KAAK,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC;QAC/D,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;QAC/B,OAAO,OAAO,CAAC,KAAK,CAAC;IACzB,CAAC;IAEO,UAAU,CAAC,OAAoB,EAAE,MAAgC;QACrE,IAAI,CAAC,aAAa,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC;YAC1C,MAAM,GAAG,GAAG,MAAgB,CAAC;YAC7B,IAAI,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC9B,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBAEzB,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;oBACvB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAA;oBACpC,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;gBAC9C,CAAC;YACL,CAAC;QACL,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { State } from "./state";
|
|
1
|
+
import { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol } from "../../../typings/index.js";
|
|
2
|
+
import { State } from "./state.js";
|
|
3
3
|
export declare class LRStack {
|
|
4
4
|
stack: LRStackItem[];
|
|
5
5
|
get current(): LRStackItem;
|
|
6
6
|
get previous(): LRStackItem;
|
|
7
7
|
shift(state: State): void;
|
|
8
|
-
reduce(rule:
|
|
9
|
-
append(symbol:
|
|
8
|
+
reduce(rule: RuntimeGrammarProductionRule): void;
|
|
9
|
+
append(symbol: RuntimeGrammarRuleSymbol): void;
|
|
10
10
|
static NewItem(): LRStackItem;
|
|
11
11
|
}
|
|
12
12
|
interface LRStackItem {
|
|
13
13
|
children: LRStackItem[];
|
|
14
14
|
state: State;
|
|
15
|
-
symbol:
|
|
16
|
-
rule:
|
|
15
|
+
symbol: RuntimeGrammarRuleSymbol;
|
|
16
|
+
rule: RuntimeGrammarProductionRule;
|
|
17
17
|
value: any;
|
|
18
18
|
}
|
|
19
19
|
export {};
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.LRStack = void 0;
|
|
4
|
-
class LRStack {
|
|
1
|
+
export class LRStack {
|
|
5
2
|
stack = [];
|
|
6
3
|
get current() {
|
|
7
4
|
return this.stack[this.stack.length - 1];
|
|
@@ -35,5 +32,4 @@ class LRStack {
|
|
|
35
32
|
};
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
exports.LRStack = LRStack;
|
|
39
35
|
//# sourceMappingURL=stack.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/stack.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stack.js","sourceRoot":"","sources":["../../../../src/parser/algorithms/lrk/stack.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,OAAO;IAEhB,KAAK,GAAkB,EAAE,CAAC;IAE1B,IAAI,OAAO;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAED,IAAI,QAAQ;QACR,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC7C,CAAC;IAGD,KAAK,CAAC,KAAY;QACd,IAAI,CAAC,OAAO,CAAC,KAAK,GAAG,KAAK,CAAC;IAC/B,CAAC;IAED,MAAM,CAAC,IAAkC;QACrC,MAAM,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;QAC5B,MAAM,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC;QAC9B,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;QACxC,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;QACd,CAAC,CAAC,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC;QACrB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACvB,CAAC;IAED,MAAM,CAAC,MAAgC;QACnC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC,CAAA;QAClC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IACjC,CAAC;IAED,MAAM,CAAC,OAAO;QACV,OAAO;YACH,QAAQ,EAAE,EAAE;YACZ,KAAK,EAAE,IAAI;YACX,MAAM,EAAE,IAAI;YACZ,IAAI,EAAE,IAAI;YACV,KAAK,EAAE,IAAI;SACd,CAAA;IACL,CAAC;CACJ"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol } from "../../../typings/index.js";
|
|
2
2
|
export interface State {
|
|
3
3
|
items: {
|
|
4
|
-
rule:
|
|
4
|
+
rule: RuntimeGrammarProductionRule;
|
|
5
5
|
dot: number;
|
|
6
6
|
}[];
|
|
7
7
|
isFinal: boolean;
|
|
8
|
-
actions: Map<
|
|
9
|
-
goto: Map<
|
|
8
|
+
actions: Map<RuntimeGrammarRuleSymbol, string>;
|
|
9
|
+
goto: Map<RuntimeGrammarRuleSymbol, string>;
|
|
10
10
|
reduce: number;
|
|
11
|
-
rule:
|
|
11
|
+
rule: RuntimeGrammarProductionRule;
|
|
12
12
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ParserAlgorithm, RuntimeParserClass } from "../typings/index.js";
|
|
2
|
+
declare const ParserRegistry: {
|
|
3
|
+
[key: string]: ParserAlgorithm;
|
|
4
|
+
};
|
|
5
|
+
export declare function Parse(language: InstanceType<RuntimeParserClass>, input: string, options?: ParserOptions, results?: 'full' | 'first'): any;
|
|
6
|
+
interface ParserOptions {
|
|
7
|
+
algorithm: (keyof typeof ParserRegistry) | ParserAlgorithm;
|
|
8
|
+
parserOptions?: any;
|
|
9
|
+
}
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { CharacterLexer } from "../lexers/character-lexer.js";
|
|
2
|
+
import { StatefulLexer } from "../lexers/stateful-lexer.js";
|
|
3
|
+
import { TokenBuffer } from "../lexers/token-buffer.js";
|
|
4
|
+
import { CYK } from "./algorithms/cyk.js";
|
|
5
|
+
import { Earley } from "./algorithms/earley.js";
|
|
6
|
+
import { LRK } from "./algorithms/lrk/algorithm.js";
|
|
7
|
+
import { ParserUtility } from "../utility/parsing.js";
|
|
8
|
+
const ParserRegistry = {
|
|
9
|
+
earley: Earley,
|
|
10
|
+
cyk: CYK,
|
|
11
|
+
lr0: LRK
|
|
12
|
+
};
|
|
13
|
+
export function Parse(language, input, options = {
|
|
14
|
+
algorithm: 'earley',
|
|
15
|
+
parserOptions: {}
|
|
16
|
+
}, results = 'first') {
|
|
17
|
+
const tokenizer = GetTokenizer(language.artifacts);
|
|
18
|
+
tokenizer.feed(input);
|
|
19
|
+
const algorithm = typeof options.algorithm == 'function' ? options.algorithm : ParserRegistry[options.algorithm];
|
|
20
|
+
const result = algorithm({ ...language, tokens: tokenizer, utility: ParserUtility }, options.parserOptions);
|
|
21
|
+
return results == 'full' ? result : result.results[0];
|
|
22
|
+
}
|
|
23
|
+
function GetTokenizer({ lexer }) {
|
|
24
|
+
if (!lexer) {
|
|
25
|
+
return new TokenBuffer(new CharacterLexer());
|
|
26
|
+
}
|
|
27
|
+
else if ("feed" in lexer && typeof lexer.feed == 'function') {
|
|
28
|
+
return new TokenBuffer(lexer);
|
|
29
|
+
}
|
|
30
|
+
else if ('states' in lexer) {
|
|
31
|
+
return new TokenBuffer(new StatefulLexer(lexer));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=parse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/parser/parse.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,cAAc,GAAuC;IACvD,MAAM,EAAE,MAAM;IACd,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;CACX,CAAA;AAED,MAAM,UAAU,KAAK,CACjB,QAA0C,EAC1C,KAAa,EACb,UAAyB;IACrB,SAAS,EAAE,QAAQ;IACnB,aAAa,EAAE,EAAE;CACpB,EACD,UAA4B,OAAO;IAEnC,MAAM,SAAS,GAAG,YAAY,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IACnD,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACtB,MAAM,SAAS,GAAG,OAAO,OAAO,CAAC,SAAS,IAAI,UAAU,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACjH,MAAM,MAAM,GAAG,SAAS,CAAC,EAAE,GAAG,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,aAAa,EAAE,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5G,OAAO,OAAO,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,YAAY,CAAC,EAAE,KAAK,EAAmC;IAC5D,IAAI,CAAC,KAAK,EAAE,CAAC;QACT,OAAO,IAAI,WAAW,CAAC,IAAI,cAAc,EAAE,CAAC,CAAC;IACjD,CAAC;SAAM,IAAI,MAAM,IAAI,KAAK,IAAI,OAAO,KAAK,CAAC,IAAI,IAAI,UAAU,EAAE,CAAC;QAC5D,OAAO,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IAClC,CAAC;SAAM,IAAI,QAAQ,IAAI,KAAK,EAAE,CAAC;QAC3B,OAAO,IAAI,WAAW,CAAC,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,CAAC;AACL,CAAC"}
|
package/build/parser/parser.d.ts
CHANGED
|
@@ -1,23 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ParserAlgorithm, RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeLanguageDefinition, RuntimeLexerToken } from "../typings/index.js";
|
|
2
2
|
declare const ParserRegistry: {
|
|
3
3
|
[key: string]: ParserAlgorithm;
|
|
4
4
|
};
|
|
5
|
-
export declare function Parse(language:
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
private options;
|
|
11
|
-
constructor(language: LanguageDefinition, options?: ParserOptions);
|
|
12
|
-
run(input: string): {
|
|
13
|
-
results: any[];
|
|
14
|
-
};
|
|
15
|
-
private getTokenQueue;
|
|
16
|
-
}
|
|
17
|
-
export declare abstract class ParserUtility {
|
|
18
|
-
static SymbolMatchesToken(symbol: GrammarRuleSymbol, token: LexerToken): boolean;
|
|
19
|
-
static SymbolIsTerminal(symbol: GrammarRuleSymbol): boolean;
|
|
20
|
-
static PostProcess(rule: GrammarRule, data: any, meta?: any): any;
|
|
5
|
+
export declare function Parse(language: RuntimeLanguageDefinition, input: string, options?: ParserOptions, results?: 'full' | 'first'): any;
|
|
6
|
+
export declare class ParserUtility {
|
|
7
|
+
static SymbolMatchesToken(symbol: RuntimeGrammarRuleSymbol, token: RuntimeLexerToken): boolean;
|
|
8
|
+
static SymbolIsTerminal(symbol: RuntimeGrammarRuleSymbol): boolean;
|
|
9
|
+
static PostProcess(rule: RuntimeGrammarProductionRule, data: any, meta?: any): any;
|
|
21
10
|
}
|
|
22
11
|
interface ParserOptions {
|
|
23
12
|
algorithm: (keyof typeof ParserRegistry) | ParserAlgorithm;
|
package/build/parser/parser.js
CHANGED
|
@@ -1,51 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const cyk_1 = require("./algorithms/cyk");
|
|
8
|
-
const earley_1 = require("./algorithms/earley");
|
|
9
|
-
const algorithm_1 = require("./algorithms/lrk/algorithm");
|
|
1
|
+
import { CharacterLexer } from "../lexers/character-lexer.js";
|
|
2
|
+
import { StatefulLexer } from "../lexers/stateful-lexer.js";
|
|
3
|
+
import { TokenBuffer } from "../lexers/token-buffer.js";
|
|
4
|
+
import { CYK } from "./algorithms/cyk.js";
|
|
5
|
+
import { Earley } from "./algorithms/earley.js";
|
|
6
|
+
import { LRK } from "./algorithms/lrk/algorithm.js";
|
|
10
7
|
const ParserRegistry = {
|
|
11
|
-
earley:
|
|
12
|
-
cyk:
|
|
13
|
-
lr0:
|
|
8
|
+
earley: Earley,
|
|
9
|
+
cyk: CYK,
|
|
10
|
+
lr0: LRK
|
|
14
11
|
};
|
|
15
|
-
function Parse(language, input, options
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
export function Parse(language, input, options = {
|
|
13
|
+
algorithm: 'earley',
|
|
14
|
+
parserOptions: {}
|
|
15
|
+
}, results = 'first') {
|
|
16
|
+
const tokenizer = GetTokenizer(language);
|
|
17
|
+
tokenizer.feed(input);
|
|
18
|
+
const algorithm = typeof options.algorithm == 'function' ? options.algorithm : ParserRegistry[options.algorithm];
|
|
19
|
+
const result = algorithm({ ...language, tokens: tokenizer, utility: ParserUtility }, options.parserOptions);
|
|
20
|
+
return results == 'full' ? result : result.results[0];
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
options;
|
|
23
|
-
constructor(language, options = { algorithm: 'earley', parserOptions: {} }) {
|
|
24
|
-
this.language = language;
|
|
25
|
-
this.options = options;
|
|
22
|
+
function GetTokenizer({ lexer }) {
|
|
23
|
+
if (!lexer) {
|
|
24
|
+
return new TokenBuffer(new CharacterLexer());
|
|
26
25
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
tokenQueue.feed(input);
|
|
30
|
-
if (typeof this.options.algorithm == 'function')
|
|
31
|
-
return this.options.algorithm({ ...this.language, tokens: tokenQueue, utility: ParserUtility }, this.options.parserOptions);
|
|
32
|
-
return ParserRegistry[this.options.algorithm]({ ...this.language, tokens: tokenQueue, utility: ParserUtility }, this.options.parserOptions);
|
|
26
|
+
else if ("feed" in lexer && typeof lexer.feed == 'function') {
|
|
27
|
+
return new TokenBuffer(lexer);
|
|
33
28
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (!lexer) {
|
|
37
|
-
return new token_buffer_1.TokenBuffer(new character_lexer_1.CharacterLexer());
|
|
38
|
-
}
|
|
39
|
-
else if ("feed" in lexer && typeof lexer.feed == 'function') {
|
|
40
|
-
return new token_buffer_1.TokenBuffer(lexer);
|
|
41
|
-
}
|
|
42
|
-
else if ('states' in lexer) {
|
|
43
|
-
return new token_buffer_1.TokenBuffer(new stateful_lexer_1.StatefulLexer(lexer));
|
|
44
|
-
}
|
|
29
|
+
else if ('states' in lexer) {
|
|
30
|
+
return new TokenBuffer(new StatefulLexer(lexer));
|
|
45
31
|
}
|
|
46
32
|
}
|
|
47
|
-
|
|
48
|
-
class ParserUtility {
|
|
33
|
+
export class ParserUtility {
|
|
49
34
|
static SymbolMatchesToken(symbol, token) {
|
|
50
35
|
if (typeof symbol === 'string')
|
|
51
36
|
throw 'Attempted to match token against non-terminal';
|
|
@@ -70,5 +55,4 @@ class ParserUtility {
|
|
|
70
55
|
return data;
|
|
71
56
|
}
|
|
72
57
|
}
|
|
73
|
-
exports.ParserUtility = ParserUtility;
|
|
74
58
|
//# sourceMappingURL=parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser/parser.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"parser.js","sourceRoot":"","sources":["../../src/parser/parser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAC5D,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,GAAG,EAAE,MAAM,+BAA+B,CAAC;AAEpD,MAAM,cAAc,GAAuC;IACvD,MAAM,EAAE,MAAM;IACd,GAAG,EAAE,GAAG;IACR,GAAG,EAAE,GAAG;CACX,CAAA;AAED,MAAM,UAAU,KAAK,CACjB,QAAmC,EACn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AAI,UAAU;YAC3B,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;QACzB,IAAI,CAAC,MAAM;YACP,OAAM;QACV,IAAI,MAAM,IAAI,MAAM;YAChB,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;QACpC,IAAI,OAAO,IAAI,MAAM;YACjB,OAAO,MAAM,CAAC,KAAK,KAAK,KAAK,CAAC,IAAI,IAAI,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACvE,IAAI,SAAS,IAAI,MAAM;YACnB,OAAO,MAAM,CAAC,OAAO,KAAK,KAAK,CAAC,KAAK,CAAC;IAC9C,CAAC;IAED,MAAM,CAAC,gBAAgB,CAAC,MAAgC;QACpD,OAAO,OAAO,MAAM,IAAI,QAAQ,CAAC;IACrC,CAAC;IAED,MAAM,CAAC,WAAW,CAAC,IAAkC,EAAE,IAAS,EAAE,IAAU;QACxE,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACnB,OAAO,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/index.ts","../src/generator/generator.ts","../src/generator/index.ts","../src/generator/state.ts","../src/generator/artifacts/basic.ts","../src/generator/artifacts/lexer.ts","../src/generator/artifacts/lr.ts","../src/generator/grammars/index.ts","../src/generator/grammars/v1.ts","../src/generator/grammars/v2.ts","../src/generator/import-resolvers/auto.ts","../src/generator/import-resolvers/browser.ts","../src/generator/import-resolvers/filesystem.ts","../src/generator/stringify/common.ts","../src/generator/stringify/javascript.ts","../src/generator/stringify/exports/javascript.ts","../src/generator/stringify/exports/json.ts","../src/generator/stringify/exports/registry.ts","../src/generator/stringify/exports/typescript.ts","../src/generator/stringify/grammar/v2.ts","../src/lexers/character-lexer.ts","../src/lexers/stateful-lexer.ts","../src/lexers/token-buffer.ts","../src/parser/parse.ts","../src/parser/algorithms/cyk.ts","../src/parser/algorithms/earley.ts","../src/parser/algorithms/lrk/algorithm.ts","../src/parser/algorithms/lrk/bimap.ts","../src/parser/algorithms/lrk/canonical-collection.ts","../src/parser/algorithms/lrk/closure.ts","../src/parser/algorithms/lrk/stack.ts","../src/parser/algorithms/lrk/state.ts","../src/typings/ast.ts","../src/typings/common.ts","../src/typings/generator.ts","../src/typings/index.ts","../src/typings/runtime.ts","../src/utility/format.ts","../src/utility/general.ts","../src/utility/index.ts","../src/utility/lint.ts","../src/utility/monarch.ts","../src/utility/parsing.ts","../src/utility/text-format.ts"],"version":"5.7.2"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { Dictionary } from "./common.js";
|
|
2
|
+
export type AST = ASTDirectives[];
|
|
3
|
+
export type ASTJavascriptLifecycleLiteral = {
|
|
4
|
+
lifecycle: string;
|
|
5
|
+
path?: boolean;
|
|
6
|
+
js: ASTJavaScriptLiteral;
|
|
7
|
+
};
|
|
8
|
+
export type ASTJavaScriptLiteral = {
|
|
9
|
+
js: string;
|
|
10
|
+
};
|
|
11
|
+
export type ASTJavaScriptTemplate = {
|
|
12
|
+
template: string;
|
|
13
|
+
};
|
|
14
|
+
export interface ASTJavaScriptBuiltin {
|
|
15
|
+
builtin: string;
|
|
16
|
+
}
|
|
17
|
+
export interface ASTImport {
|
|
18
|
+
import: string;
|
|
19
|
+
path?: boolean;
|
|
20
|
+
alias?: string;
|
|
21
|
+
}
|
|
22
|
+
export interface ASTConfig {
|
|
23
|
+
config: Dictionary<any>;
|
|
24
|
+
}
|
|
25
|
+
export interface ASTGrammar {
|
|
26
|
+
grammar: {
|
|
27
|
+
config?: Dictionary<any>;
|
|
28
|
+
rules: ASTGrammarProduction[];
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface ASTLexer {
|
|
32
|
+
lexer: ASTLexerConfig;
|
|
33
|
+
}
|
|
34
|
+
export interface ASTLexerConfig {
|
|
35
|
+
start?: string;
|
|
36
|
+
states: {
|
|
37
|
+
name: string;
|
|
38
|
+
state: (ASTLexerState | ASTLexerStateSpan);
|
|
39
|
+
}[];
|
|
40
|
+
}
|
|
41
|
+
export interface ASTGrammarProduction {
|
|
42
|
+
name: string;
|
|
43
|
+
expressions: ASTGrammarProductionRule[];
|
|
44
|
+
postprocess?: ASTJavaScriptLiteral | ASTJavaScriptTemplate | ASTJavaScriptBuiltin;
|
|
45
|
+
}
|
|
46
|
+
export interface ASTGrammarProductionRule {
|
|
47
|
+
symbols: ASTGrammarSymbol[];
|
|
48
|
+
postprocess?: ASTJavaScriptLiteral | ASTJavaScriptTemplate | ASTJavaScriptBuiltin;
|
|
49
|
+
}
|
|
50
|
+
export type ASTGrammarSymbol = ASTGrammarSymbolAlias & (ASTGrammarSymbolNonTerminal | ASTGrammarSymbolRegex | ASTGrammarSymbolToken | ASTGrammarSymbolLiteral | ASTGrammarSymbolRepeat | ASTGrammarSymbolGroup);
|
|
51
|
+
export type ASTGrammarSymbolAlias = {
|
|
52
|
+
alias?: string;
|
|
53
|
+
};
|
|
54
|
+
export interface ASTGrammarSymbolGroup {
|
|
55
|
+
subexpression: ASTGrammarProductionRule[];
|
|
56
|
+
}
|
|
57
|
+
export interface ASTGrammarSymbolRepeat {
|
|
58
|
+
expression: ASTGrammarSymbol;
|
|
59
|
+
repeat: "+" | "*" | "?";
|
|
60
|
+
}
|
|
61
|
+
export interface ASTGrammarSymbolNonTerminal {
|
|
62
|
+
rule: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ASTGrammarSymbolRegex {
|
|
65
|
+
regex: string;
|
|
66
|
+
flags?: string;
|
|
67
|
+
quote?: string;
|
|
68
|
+
}
|
|
69
|
+
export interface ASTGrammarSymbolToken {
|
|
70
|
+
token: string;
|
|
71
|
+
}
|
|
72
|
+
export interface ASTGrammarSymbolLiteral {
|
|
73
|
+
literal: string;
|
|
74
|
+
insensitive?: boolean;
|
|
75
|
+
}
|
|
76
|
+
export type ASTDirectives = (ASTJavascriptLifecycleLiteral | ASTImport | ASTConfig | ASTGrammar | ASTLexer);
|
|
77
|
+
export interface ASTLexerState {
|
|
78
|
+
unmatched?: ASTLexerStateNonMatchRule;
|
|
79
|
+
default?: ASTLexerStateMatchRule;
|
|
80
|
+
rules: (ASTLexerStateImportRule | ASTLexerStateMatchRule | ASTLexerStateSpan)[];
|
|
81
|
+
}
|
|
82
|
+
export interface ASTLexerStateSpan {
|
|
83
|
+
config?: {
|
|
84
|
+
transition?: "goto" | "set";
|
|
85
|
+
};
|
|
86
|
+
span: {
|
|
87
|
+
name: string;
|
|
88
|
+
state: (ASTLexerState);
|
|
89
|
+
}[];
|
|
90
|
+
}
|
|
91
|
+
export interface ASTLexerStateImportRule {
|
|
92
|
+
import: string[];
|
|
93
|
+
pop?: number | 'all';
|
|
94
|
+
inset?: number;
|
|
95
|
+
goto?: string;
|
|
96
|
+
set?: string;
|
|
97
|
+
stay?: boolean;
|
|
98
|
+
}
|
|
99
|
+
export interface ASTLexerStateMatchRule {
|
|
100
|
+
when: string | ASTGrammarSymbolRegex;
|
|
101
|
+
type?: string;
|
|
102
|
+
tag?: string[];
|
|
103
|
+
before?: boolean;
|
|
104
|
+
skip?: boolean;
|
|
105
|
+
highlight?: string;
|
|
106
|
+
open?: string;
|
|
107
|
+
close?: string;
|
|
108
|
+
embed?: string;
|
|
109
|
+
unembed?: boolean;
|
|
110
|
+
pop?: number | 'all';
|
|
111
|
+
stay?: true;
|
|
112
|
+
inset?: number;
|
|
113
|
+
goto?: string;
|
|
114
|
+
set?: string;
|
|
115
|
+
}
|
|
116
|
+
export interface ASTLexerStateNonMatchRule {
|
|
117
|
+
type?: string;
|
|
118
|
+
tag?: string[];
|
|
119
|
+
before?: undefined;
|
|
120
|
+
skip?: undefined;
|
|
121
|
+
highlight?: string;
|
|
122
|
+
open?: string;
|
|
123
|
+
close?: string;
|
|
124
|
+
embed?: string;
|
|
125
|
+
unembed?: boolean;
|
|
126
|
+
pop?: number | 'all';
|
|
127
|
+
inset?: number;
|
|
128
|
+
goto?: string;
|
|
129
|
+
set?: string;
|
|
130
|
+
}
|
|
131
|
+
export type StateList = {
|
|
132
|
+
name: string;
|
|
133
|
+
state: (ASTLexerState | ASTLexerStateSpan);
|
|
134
|
+
}[];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/typings/ast.ts"],"names":[],"mappings":"AA2CC,CAAC"}
|