grammar-well 2.0.7 → 2.2.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/build/generator/artifacts/basic.d.ts +1 -1
- package/build/generator/artifacts/basic.js.map +1 -1
- package/build/generator/artifacts/lexer.d.ts +2 -2
- package/build/generator/artifacts/lexer.js +1 -1
- package/build/generator/artifacts/lexer.js.map +1 -1
- package/build/generator/artifacts/lr.d.ts +5 -5
- package/build/generator/artifacts/lr.js +2 -2
- package/build/generator/artifacts/lr.js.map +1 -1
- package/build/generator/generator.d.ts +3 -3
- package/build/generator/generator.js +3 -3
- package/build/generator/generator.js.map +1 -1
- package/build/generator/grammars/index.d.ts +2 -2
- package/build/generator/grammars/index.js +2 -2
- package/build/generator/import-resolvers/auto.d.ts +1 -1
- package/build/generator/import-resolvers/browser.d.ts +1 -1
- package/build/generator/import-resolvers/browser.js.map +1 -1
- package/build/generator/import-resolvers/dictionary.d.ts +1 -1
- package/build/generator/import-resolvers/dictionary.js.map +1 -1
- package/build/generator/import-resolvers/filesystem.d.ts +1 -1
- package/build/generator/index.d.ts +3 -3
- package/build/generator/index.js +3 -3
- package/build/generator/state.d.ts +1 -1
- package/build/generator/stringify/common.d.ts +2 -2
- package/build/generator/stringify/common.js.map +1 -1
- package/build/generator/stringify/exports/javascript.d.ts +1 -1
- package/build/generator/stringify/exports/json.d.ts +1 -1
- package/build/generator/stringify/exports/registry.d.ts +6 -6
- package/build/generator/stringify/exports/typescript.d.ts +1 -1
- package/build/generator/stringify/grammar/v2.d.ts +1 -1
- package/build/generator/stringify/javascript.d.ts +2 -2
- package/build/generator/stringify/javascript.js.map +1 -1
- package/build/index.d.ts +7 -7
- package/build/index.js +7 -7
- package/build/lexers/character-lexer.d.ts +1 -1
- package/build/lexers/stateful-lexer.d.ts +1 -1
- package/build/lexers/token-buffer.d.ts +3 -3
- package/build/lexers/token-buffer.js +2 -2
- package/build/lexers/token-buffer.js.map +1 -1
- package/build/parser/algorithms/cyk.d.ts +2 -2
- package/build/parser/algorithms/earley.d.ts +15 -12
- package/build/parser/algorithms/earley.js +39 -14
- package/build/parser/algorithms/earley.js.map +1 -1
- package/build/parser/algorithms/lrk/algorithm.d.ts +2 -2
- package/build/parser/algorithms/lrk/algorithm.js +31 -21
- package/build/parser/algorithms/lrk/algorithm.js.map +1 -1
- package/build/parser/algorithms/lrk/canonical-collection.d.ts +10 -10
- package/build/parser/algorithms/lrk/canonical-collection.js +73 -49
- package/build/parser/algorithms/lrk/canonical-collection.js.map +1 -1
- package/build/parser/algorithms/lrk/closure.d.ts +1 -1
- package/build/parser/algorithms/lrk/closure.js.map +1 -1
- package/build/parser/algorithms/lrk/stack.d.ts +8 -18
- package/build/parser/algorithms/lrk/stack.js +11 -24
- package/build/parser/algorithms/lrk/stack.js.map +1 -1
- package/build/parser/algorithms/lrk/state.d.ts +1 -1
- package/build/parser/algorithms/lrk/typings.d.ts +16 -0
- package/build/parser/algorithms/lrk/typings.js +2 -0
- package/build/parser/algorithms/lrk/typings.js.map +1 -0
- package/build/parser/parse.d.ts +1 -1
- package/build/typings/ast.d.ts +1 -1
- package/build/typings/generator.d.ts +4 -4
- package/build/typings/index.d.ts +8 -8
- package/build/typings/index.js +4 -4
- package/build/typings/runtime.d.ts +3 -3
- package/build/utility/format.js +3 -3
- package/build/utility/general.d.ts +2 -2
- package/build/utility/general.js +1 -1
- package/build/utility/general.js.map +1 -1
- package/build/utility/index.d.ts +4 -4
- package/build/utility/index.js +4 -4
- package/build/utility/lint.d.ts +1 -1
- package/build/utility/monarch.d.ts +1 -1
- package/build/utility/parsing.d.ts +2 -2
- package/build/utility/text-format.d.ts +2 -2
- package/build/version.json +1 -1
- package/package.json +8 -9
- package/src/generator/artifacts/basic.ts +6 -4
- package/src/generator/artifacts/lexer.ts +6 -4
- package/src/generator/artifacts/lr.ts +10 -7
- package/src/generator/generator.ts +17 -11
- package/src/generator/grammars/index.ts +2 -2
- package/src/generator/grammars/v1.ts +1 -1
- package/src/generator/grammars/v2.ts +1 -1
- package/src/generator/import-resolvers/auto.ts +3 -3
- package/src/generator/import-resolvers/browser.ts +5 -2
- package/src/generator/import-resolvers/dictionary.ts +5 -2
- package/src/generator/import-resolvers/filesystem.ts +1 -1
- package/src/generator/index.ts +3 -3
- package/src/generator/state.ts +1 -1
- package/src/generator/stringify/common.ts +6 -3
- package/src/generator/stringify/exports/javascript.ts +1 -1
- package/src/generator/stringify/exports/json.ts +1 -1
- package/src/generator/stringify/exports/registry.ts +4 -4
- package/src/generator/stringify/exports/typescript.ts +1 -1
- package/src/generator/stringify/grammar/v2.ts +1 -1
- package/src/generator/stringify/javascript.ts +12 -8
- package/src/index.ts +7 -7
- package/src/lexers/character-lexer.ts +1 -1
- package/src/lexers/stateful-lexer.ts +1 -1
- package/src/lexers/token-buffer.ts +16 -3
- package/src/parser/algorithms/cyk.ts +4 -4
- package/src/parser/algorithms/earley.ts +68 -20
- package/src/parser/algorithms/lrk/algorithm.ts +40 -25
- package/src/parser/algorithms/lrk/canonical-collection.ts +84 -55
- package/src/parser/algorithms/lrk/stack.ts +12 -37
- package/src/parser/algorithms/lrk/typings.ts +13 -0
- package/src/parser/parse.ts +8 -8
- package/src/typings/ast.ts +1 -1
- package/src/typings/generator.ts +4 -4
- package/src/typings/index.ts +8 -8
- package/src/typings/runtime.ts +3 -3
- package/src/utility/format.ts +4 -4
- package/src/utility/general.ts +4 -3
- package/src/utility/index.ts +4 -4
- package/src/utility/lint.ts +1 -1
- package/src/utility/monarch.ts +1 -1
- package/src/utility/parsing.ts +1 -1
- package/src/utility/text-format.ts +2 -2
- package/src/version.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/src/parser/algorithms/lrk/closure.ts +0 -37
- package/src/parser/algorithms/lrk/state.ts +0 -10
package/build/parser/parse.d.ts
CHANGED
package/build/typings/ast.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { GeneratorState } from "../generator/state.
|
|
2
|
-
import { ASTGrammarSymbolLiteral, ASTGrammarSymbolNonTerminal, ASTGrammarSymbolRegex, ASTGrammarSymbolToken, ASTJavaScriptBuiltin, ASTJavaScriptLiteral, ASTJavaScriptTemplate, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateNonMatchRule } from "./ast.
|
|
3
|
-
import { Dictionary } from "./common.
|
|
4
|
-
import { ImportResolver, ImportResolverConstructor } from "./index.
|
|
1
|
+
import { GeneratorState } from "../generator/state.ts";
|
|
2
|
+
import type { ASTGrammarSymbolLiteral, ASTGrammarSymbolNonTerminal, ASTGrammarSymbolRegex, ASTGrammarSymbolToken, ASTJavaScriptBuiltin, ASTJavaScriptLiteral, ASTJavaScriptTemplate, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateNonMatchRule } from "./ast.ts";
|
|
3
|
+
import type { Dictionary } from "./common.ts";
|
|
4
|
+
import type { ImportResolver, ImportResolverConstructor } from "./index.ts";
|
|
5
5
|
export type GenerateOptions = GeneratorOptions & {
|
|
6
6
|
output?: GeneratorOutputOptions;
|
|
7
7
|
};
|
package/build/typings/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { TokenBuffer } from "../lexers/token-buffer.
|
|
2
|
-
import { ParserUtility } from "../utility/parsing.
|
|
3
|
-
import { ASTLexerStateNonMatchRule } from "./ast.
|
|
4
|
-
import { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeParserClass, RuntimeLexerStateMatchRule } from "./runtime.
|
|
5
|
-
export * from './ast.
|
|
6
|
-
export * from './common.
|
|
7
|
-
export * from './generator.
|
|
8
|
-
export * from './runtime.
|
|
1
|
+
import type { TokenBuffer } from "../lexers/token-buffer.ts";
|
|
2
|
+
import type { ParserUtility } from "../utility/parsing.ts";
|
|
3
|
+
import type { ASTLexerStateNonMatchRule } from "./ast.ts";
|
|
4
|
+
import type { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeParserClass, RuntimeLexerStateMatchRule } from "./runtime.ts";
|
|
5
|
+
export * from './ast.ts';
|
|
6
|
+
export * from './common.ts';
|
|
7
|
+
export * from './generator.ts';
|
|
8
|
+
export * from './runtime.ts';
|
|
9
9
|
export interface ImportResolver {
|
|
10
10
|
path(path: string): string;
|
|
11
11
|
body(path: string): Promise<string>;
|
package/build/typings/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./ast.js";
|
|
2
|
+
export * from "./common.js";
|
|
3
|
+
export * from "./generator.js";
|
|
4
|
+
export * from "./runtime.js";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LRState } from "./index.
|
|
2
|
-
import { ASTGrammarSymbolLiteral, ASTGrammarSymbolToken, ASTLexerStateNonMatchRule } from "./ast.
|
|
3
|
-
import { Dictionary } from "./common.
|
|
1
|
+
import type { LRState } from "./index.ts";
|
|
2
|
+
import type { ASTGrammarSymbolLiteral, ASTGrammarSymbolToken, ASTLexerStateNonMatchRule } from "./ast.ts";
|
|
3
|
+
import type { Dictionary } from "./common.ts";
|
|
4
4
|
export interface RuntimeParserClass {
|
|
5
5
|
artifacts: {
|
|
6
6
|
lexer?: RuntimeLexer | RuntimeLexerConfig;
|
package/build/utility/format.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import V1Grammar from
|
|
2
|
-
import V2Grammar from
|
|
1
|
+
import V1Grammar from "../generator/grammars/v1.js";
|
|
2
|
+
import V2Grammar from "../generator/grammars/v2.js";
|
|
3
3
|
import { V2GrammarString } from "../generator/stringify/grammar/v2.js";
|
|
4
|
-
import { Parse } from
|
|
4
|
+
import { Parse } from "../parser/parse.js";
|
|
5
5
|
export function Format(source, sourceVersion = '2') {
|
|
6
6
|
const grammar = sourceVersion.toString() == '1' ? V1Grammar : V2Grammar;
|
|
7
7
|
const result = Parse(new grammar(), source);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Dictionary, GeneratorGrammarSymbol } from "../typings/index.
|
|
1
|
+
import type { Dictionary, GeneratorGrammarSymbol } from "../typings/index.ts";
|
|
2
2
|
export declare class Collection<T> {
|
|
3
3
|
categorized: Dictionary<Dictionary<number>>;
|
|
4
4
|
uncategorized: Map<T, number>;
|
|
@@ -29,13 +29,13 @@ export declare class GeneratorSymbolCollection extends Collection<GeneratorGramm
|
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
31
|
export declare class Matrix<T> {
|
|
32
|
-
private initial?;
|
|
33
32
|
private $x;
|
|
34
33
|
private $y;
|
|
35
34
|
get x(): number;
|
|
36
35
|
set x(x: number);
|
|
37
36
|
get y(): number;
|
|
38
37
|
set y(y: number);
|
|
38
|
+
private initial?;
|
|
39
39
|
matrix: GetCallbackOrValue<T>[][];
|
|
40
40
|
constructor(x: number, y: number, initial?: T | ((...args: any) => T));
|
|
41
41
|
get(x: number, y: number): T;
|
package/build/utility/general.js
CHANGED
|
@@ -67,13 +67,13 @@ export class GeneratorSymbolCollection extends Collection {
|
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
export class Matrix {
|
|
70
|
-
initial;
|
|
71
70
|
$x = 0;
|
|
72
71
|
$y = 0;
|
|
73
72
|
get x() { return this.$x; }
|
|
74
73
|
set x(x) { x != this.$x && this.resize(x, this.y); }
|
|
75
74
|
get y() { return this.$y; }
|
|
76
75
|
set y(y) { y != this.$y && this.resize(this.x, y); }
|
|
76
|
+
initial;
|
|
77
77
|
matrix = [];
|
|
78
78
|
constructor(x, y, initial) {
|
|
79
79
|
this.initial = initial;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"general.js","sourceRoot":"","sources":["../../src/utility/general.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,UAAU;IACnB,WAAW,GAAmC,EAAE,CAAC;IACjD,aAAa,GAAG,IAAI,GAAG,EAAa,CAAC;IACrC,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C,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACjC,OAAO,UAAU,CAAC,KAAY,CAAC;AACnC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAiB;IACvC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAE,CAAC;IAC1B,SAAS,QAAQ,CAAC,EAAU;QACxB,IAAI,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,CAAC;YAClB,OAAO,KAAK,CAAC,EAAE,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QAChB,MAAM,GAAG,GAAQ,KAAK,CAAC,EAAE,CAAC,CAAC;QAC3B,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YACrB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBAClC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;gBAClB,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;YAE1B,CAAC;QACL,CAAC;aAAM,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACjC,KAAK,MAAM,CAAC,IAAI,GAA6B,EAAE,CAAC;gBAC5C,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAA;YAC7B,CAAC;QACL,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;IACD,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC;AACvB,CAAC"}
|
package/build/utility/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './monarch.
|
|
2
|
-
export * from './general.
|
|
3
|
-
export * from './format.
|
|
4
|
-
export * from './parsing.
|
|
1
|
+
export * from './monarch.ts';
|
|
2
|
+
export * from './general.ts';
|
|
3
|
+
export * from './format.ts';
|
|
4
|
+
export * from './parsing.ts';
|
package/build/utility/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from
|
|
2
|
-
export * from
|
|
3
|
-
export * from
|
|
4
|
-
export * from
|
|
1
|
+
export * from "./monarch.js";
|
|
2
|
+
export * from "./general.js";
|
|
3
|
+
export * from "./format.js";
|
|
4
|
+
export * from "./parsing.js";
|
|
5
5
|
//# sourceMappingURL=index.js.map
|
package/build/utility/lint.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { RuntimeGrammarRuleSymbol, RuntimeParserClass } from "../typings/index.
|
|
1
|
+
import type { RuntimeGrammarRuleSymbol, RuntimeParserClass } from "../typings/index.ts";
|
|
2
2
|
export declare function LintGrammarSymbols(grammar: RuntimeParserClass['artifacts']['grammar']): RuntimeGrammarRuleSymbol[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeLexerToken } from "../typings/index.
|
|
1
|
+
import type { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeLexerToken } from "../typings/index.ts";
|
|
2
2
|
export declare class ParserUtility {
|
|
3
3
|
static SymbolMatchesToken(symbol: RuntimeGrammarRuleSymbol, token: RuntimeLexerToken): boolean;
|
|
4
|
-
static SymbolIsTerminal(symbol: RuntimeGrammarRuleSymbol): symbol is RegExp | import("../index.
|
|
4
|
+
static SymbolIsTerminal(symbol: RuntimeGrammarRuleSymbol): symbol is RegExp | import("../index.ts").ASTGrammarSymbolLiteral | import("../index.ts").ASTGrammarSymbolToken | ((data: RuntimeLexerToken) => boolean);
|
|
5
5
|
static PostProcess(rule: RuntimeGrammarProductionRule, data: any, meta?: any): any;
|
|
6
6
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { TokenBuffer } from "../lexers/token-buffer.
|
|
2
|
-
import { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeLexerToken } from "../typings/index.
|
|
1
|
+
import { TokenBuffer } from "../lexers/token-buffer.ts";
|
|
2
|
+
import type { RuntimeGrammarProductionRule, RuntimeGrammarRuleSymbol, RuntimeLexerToken } from "../typings/index.ts";
|
|
3
3
|
export declare class TextFormatter {
|
|
4
4
|
static UnexpectedToken(queue: TokenBuffer, expected: (RuntimeGrammarProductionRule & {
|
|
5
5
|
index?: number;
|
package/build/version.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{ "version": "2.0
|
|
1
|
+
{ "version": "2.2.0" }
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "grammar-well",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.2.0",
|
|
5
5
|
"description": "Cross-platform Parser written in TypeScript",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"prebuild": "tsc --build --clean &&
|
|
8
|
-
"grammar": "tsc --build --clean &&
|
|
7
|
+
"prebuild": "tsc --build --clean && node scripts/prebuild.ts",
|
|
8
|
+
"grammar": "tsc --build --clean && node scripts/grammar.ts",
|
|
9
9
|
"build": "tsc --build",
|
|
10
10
|
"benchmark": "node tests/performance/benchmark.js",
|
|
11
|
-
"test": "node --test --
|
|
11
|
+
"test": "node --test --test-reporter ./tests/reporter.mjs tests/**/*.spec.ts",
|
|
12
12
|
"profile": "node tests/performance/profile.js"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
@@ -32,12 +32,11 @@
|
|
|
32
32
|
"bugs": {
|
|
33
33
|
"url": "https://github.com/0x6563/grammar-well/issues"
|
|
34
34
|
},
|
|
35
|
-
"homepage": "https://
|
|
35
|
+
"homepage": "https://grammar-well.xyz",
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@types/node": "^
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"yaml": "^2.6.1"
|
|
37
|
+
"@types/node": "^25.0.3",
|
|
38
|
+
"typescript": "^5.9.3",
|
|
39
|
+
"yaml": "^2.8.2"
|
|
41
40
|
},
|
|
42
41
|
"keywords": [
|
|
43
42
|
"parser",
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { CommonGenerator } from "../stringify/common.
|
|
2
|
-
import { JavaScriptGenerator } from "../stringify/javascript.
|
|
1
|
+
import { CommonGenerator } from "../stringify/common.ts";
|
|
2
|
+
import { JavaScriptGenerator } from "../stringify/javascript.ts";
|
|
3
3
|
|
|
4
4
|
export class BasicGrammarTable {
|
|
5
|
-
|
|
6
|
-
constructor(
|
|
5
|
+
private generator: JavaScriptGenerator
|
|
6
|
+
constructor(generator: JavaScriptGenerator) {
|
|
7
|
+
this.generator = generator;
|
|
8
|
+
}
|
|
7
9
|
|
|
8
10
|
stringify(depth: number = 0) {
|
|
9
11
|
if (!this.generator.state.grammar) {
|
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import { ASTGrammarSymbolRegex, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateNonMatchRule, Dictionary, GeneratorLexerConfig, GeneratorLexerState } from "../../typings/index.
|
|
2
|
-
import { CommonGenerator } from "../stringify/common.
|
|
1
|
+
import type { ASTGrammarSymbolRegex, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateNonMatchRule, Dictionary, GeneratorLexerConfig, GeneratorLexerState } from "../../typings/index.ts";
|
|
2
|
+
import { CommonGenerator } from "../stringify/common.ts";
|
|
3
3
|
|
|
4
4
|
export class LexerArtifact {
|
|
5
5
|
private resolved = new Set<string>();
|
|
6
6
|
private resolving = new Set<string>();
|
|
7
|
-
|
|
8
|
-
constructor(
|
|
7
|
+
private lexer: GeneratorLexerConfig;
|
|
8
|
+
constructor(lexer: GeneratorLexerConfig) {
|
|
9
|
+
this.lexer = lexer;
|
|
10
|
+
}
|
|
9
11
|
|
|
10
12
|
output(depth: number = 0) {
|
|
11
13
|
if (!this.lexer)
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import { ASTGrammarSymbolNonTerminal, Dictionary, GeneratorGrammarProductionRule, GeneratorGrammarSymbol } from "../../typings/index.
|
|
2
|
-
import { Collection, GeneratorSymbolCollection } from "../../utility/general.
|
|
3
|
-
import { CommonGenerator } from "../stringify/common.
|
|
4
|
-
import { JavaScriptGenerator } from "../stringify/javascript.
|
|
1
|
+
import type { ASTGrammarSymbolNonTerminal, Dictionary, GeneratorGrammarProductionRule, GeneratorGrammarSymbol } from "../../typings/index.ts";
|
|
2
|
+
import { Collection, GeneratorSymbolCollection } from "../../utility/general.ts";
|
|
3
|
+
import { CommonGenerator } from "../stringify/common.ts";
|
|
4
|
+
import { JavaScriptGenerator } from "../stringify/javascript.ts";
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
export class LRParseTableBuilder {
|
|
8
8
|
rules: Collection<GeneratorGrammarProductionRule> = new Collection();
|
|
9
9
|
table: Dictionary<StateBuilder> = Object.create(null)
|
|
10
10
|
symbols: GeneratorSymbolCollection = new GeneratorSymbolCollection();
|
|
11
|
-
|
|
12
|
-
constructor(
|
|
11
|
+
public generator: JavaScriptGenerator;
|
|
12
|
+
constructor(generator: JavaScriptGenerator) {
|
|
13
|
+
this.generator = generator;
|
|
13
14
|
const augmented = { name: Symbol() as unknown as string, symbols: [{ rule: generator.state.grammar.start }] }
|
|
14
15
|
generator.state.grammar.rules[augmented.name] = [augmented];
|
|
15
16
|
this.addState([{ rule: augmented, dot: 0 }]);
|
|
@@ -73,8 +74,10 @@ class StateBuilder {
|
|
|
73
74
|
actions: Map<GeneratorGrammarSymbol, string> = new Map();
|
|
74
75
|
goto: Map<GeneratorGrammarSymbol, string> = new Map();
|
|
75
76
|
reduce?: GeneratorGrammarProductionRule;
|
|
77
|
+
private collection: LRParseTableBuilder;
|
|
78
|
+
constructor(collection: LRParseTableBuilder, items: StateItem[]) {
|
|
79
|
+
this.collection = collection;
|
|
76
80
|
|
|
77
|
-
constructor(private collection: LRParseTableBuilder, items: StateItem[]) {
|
|
78
81
|
const visited = new Set<GeneratorGrammarSymbol>();
|
|
79
82
|
for (const item of items) {
|
|
80
83
|
this.closure(item.rule, item.dot, visited);
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { ASTConfig, ASTDirectives, ASTGrammar, ASTGrammarProduction, ASTGrammarProductionRule, ASTGrammarSymbol, ASTGrammarSymbolGroup, ASTGrammarSymbolLiteral, ASTGrammarSymbolRepeat, ASTImport, ASTLexer, ASTLexerConfig, ASTLexerState, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateSpan, GeneratorContext, GeneratorGrammarProductionRule, GeneratorGrammarSymbol, GeneratorOptions, GeneratorExportFormat, ImportResolver, GeneratorOutputOptions, GenerateOptions, ASTJavascriptLifecycleLiteral } from "../typings/index.
|
|
1
|
+
import type { ASTConfig, ASTDirectives, ASTGrammar, ASTGrammarProduction, ASTGrammarProductionRule, ASTGrammarSymbol, ASTGrammarSymbolGroup, ASTGrammarSymbolLiteral, ASTGrammarSymbolRepeat, ASTImport, ASTLexer, ASTLexerConfig, ASTLexerState, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateSpan, GeneratorContext, GeneratorGrammarProductionRule, GeneratorGrammarSymbol, GeneratorOptions, GeneratorExportFormat, ImportResolver, GeneratorOutputOptions, GenerateOptions, ASTJavascriptLifecycleLiteral } from "../typings/index.ts";
|
|
2
2
|
|
|
3
|
-
import { Parse } from "../parser/parse.
|
|
4
|
-
import GrammarV1 from './grammars/v1.
|
|
5
|
-
import GrammarV2 from './grammars/v2.
|
|
3
|
+
import { Parse } from "../parser/parse.ts";
|
|
4
|
+
import GrammarV1 from './grammars/v1.ts';
|
|
5
|
+
import GrammarV2 from './grammars/v2.ts';
|
|
6
6
|
|
|
7
7
|
import BuiltInRegistry from "./builtin/registry.json" with {type: 'json'};
|
|
8
|
-
import { GeneratorState } from "./state.
|
|
9
|
-
import { ExportsRegistry } from "./stringify/exports/registry.
|
|
10
|
-
import { JavaScriptGenerator } from "./stringify/javascript.
|
|
11
|
-
import { BrowserImportResolver } from "./import-resolvers/browser.
|
|
8
|
+
import { GeneratorState } from "./state.ts";
|
|
9
|
+
import { ExportsRegistry } from "./stringify/exports/registry.ts";
|
|
10
|
+
import { JavaScriptGenerator } from "./stringify/javascript.ts";
|
|
11
|
+
import { BrowserImportResolver } from "./import-resolvers/browser.ts";
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
export async function Generate(source: string, config?: GenerateOptions): Promise<ReturnType<Generator['output']>>;
|
|
@@ -23,16 +23,22 @@ export async function Generate(source: string | ASTDirectives | (ASTDirectives[]
|
|
|
23
23
|
export const NAME_DELIMITER = '.';
|
|
24
24
|
export class Generator {
|
|
25
25
|
private state = new GeneratorState();
|
|
26
|
+
private config: GeneratorOptions;
|
|
27
|
+
private context: GeneratorContext;
|
|
28
|
+
private aliasPrefix: string;
|
|
26
29
|
|
|
27
30
|
constructor(
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
config: GeneratorOptions = {},
|
|
32
|
+
context: GeneratorContext = {
|
|
30
33
|
imported: new Set(),
|
|
31
34
|
resolver: undefined as ImportResolver,
|
|
32
35
|
state: undefined as GeneratorState
|
|
33
36
|
},
|
|
34
|
-
|
|
37
|
+
aliasPrefix: string = ''
|
|
35
38
|
) {
|
|
39
|
+
this.config = config;
|
|
40
|
+
this.context = context;
|
|
41
|
+
this.aliasPrefix = aliasPrefix;
|
|
36
42
|
|
|
37
43
|
if (typeof config.resolver == 'function') {
|
|
38
44
|
this.context.resolver = new config.resolver(config.basedir);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default as V1Grammar } from './v1.
|
|
2
|
-
export { default as V2Grammar } from './v2.
|
|
1
|
+
export { default as V1Grammar } from './v1.ts';
|
|
2
|
+
export { default as V2Grammar } from './v2.ts';
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ImportResolverConstructor } from "../../typings/index.
|
|
1
|
+
import type { ImportResolverConstructor } from "../../typings/index.ts";
|
|
2
2
|
let resolver;
|
|
3
3
|
|
|
4
4
|
if (typeof process && process?.release?.name?.search(/node|io\.js/) >= 0) {
|
|
5
|
-
const { FileSystemResolver } = await import("./filesystem.
|
|
5
|
+
const { FileSystemResolver } = await import("./filesystem.ts");
|
|
6
6
|
resolver = FileSystemResolver;
|
|
7
7
|
} else {
|
|
8
|
-
const { BrowserImportResolver } = await import("./browser.
|
|
8
|
+
const { BrowserImportResolver } = await import("./browser.ts");
|
|
9
9
|
resolver = BrowserImportResolver;
|
|
10
10
|
}
|
|
11
11
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { ImportResolver } from "../../typings/index.
|
|
1
|
+
import type { ImportResolver } from "../../typings/index.ts";
|
|
2
2
|
|
|
3
3
|
export class BrowserImportResolver implements ImportResolver {
|
|
4
|
-
|
|
4
|
+
private baseURL: string;
|
|
5
|
+
constructor(baseURL: string) {
|
|
6
|
+
this.baseURL = baseURL;
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
path(path: string) {
|
|
7
10
|
return (new URL(path, this.baseURL)).href;
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { ImportResolver } from "../../typings";
|
|
1
|
+
import { type ImportResolver } from "../../typings/index.ts";
|
|
2
2
|
|
|
3
3
|
export class DictionaryResolver implements ImportResolver {
|
|
4
|
-
|
|
4
|
+
private files: { [key: string]: string }
|
|
5
|
+
constructor(files: { [key: string]: string }) {
|
|
6
|
+
this.files = files;
|
|
7
|
+
}
|
|
5
8
|
|
|
6
9
|
path(path: string) {
|
|
7
10
|
if (path in this.files)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readFile } from 'fs/promises';
|
|
2
2
|
import { dirname, resolve } from 'path';
|
|
3
|
-
import { ImportResolver } from "../../typings/index.
|
|
3
|
+
import type { ImportResolver } from "../../typings/index.ts";
|
|
4
4
|
|
|
5
5
|
export class FileSystemResolver implements ImportResolver {
|
|
6
6
|
private baseDir: string;
|
package/src/generator/index.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './generator.
|
|
2
|
-
export { default as V1Grammar } from './grammars/v1.
|
|
3
|
-
export { default as V2Grammar } from './grammars/v2.
|
|
1
|
+
export * from './generator.ts';
|
|
2
|
+
export { default as V1Grammar } from './grammars/v1.ts';
|
|
3
|
+
export { default as V2Grammar } from './grammars/v2.ts';
|
package/src/generator/state.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GeneratorGrammarProductionRule, GeneratorLexerConfig, GeneratorLexerState, GeneratorStateGrammar } from "../typings/index.
|
|
1
|
+
import type { GeneratorGrammarProductionRule, GeneratorLexerConfig, GeneratorLexerState, GeneratorStateGrammar } from "../typings/index.ts";
|
|
2
2
|
import version from "../version.json" with { type: "json" };
|
|
3
3
|
export class GeneratorState {
|
|
4
4
|
grammar?: GeneratorStateGrammar;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { ASTGrammarSymbolLiteral, ASTGrammarSymbolNonTerminal, ASTGrammarSymbolRegex, ASTGrammarSymbolToken, GeneratorGrammarSymbol } from "../../typings/index.
|
|
2
|
-
import { GeneratorState } from "../state.
|
|
1
|
+
import type { ASTGrammarSymbolLiteral, ASTGrammarSymbolNonTerminal, ASTGrammarSymbolRegex, ASTGrammarSymbolToken, GeneratorGrammarSymbol } from "../../typings/index.ts";
|
|
2
|
+
import { GeneratorState } from "../state.ts";
|
|
3
3
|
|
|
4
4
|
export class CommonGenerator {
|
|
5
|
-
|
|
5
|
+
public state: GeneratorState;
|
|
6
|
+
constructor(state: GeneratorState) {
|
|
7
|
+
this.state = state;
|
|
8
|
+
}
|
|
6
9
|
|
|
7
10
|
static NewLine(indent: number) {
|
|
8
11
|
return '\n' + ' '.repeat(indent * 4);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
|
|
2
|
-
import { JavaScriptGenerator } from "../javascript.
|
|
3
|
-
import { CJSOutput, ESMOutput } from "./javascript.
|
|
4
|
-
import { JSONFormatter } from "./json.
|
|
5
|
-
import { TypescriptFormat } from "./typescript.
|
|
2
|
+
import { JavaScriptGenerator } from "../javascript.ts";
|
|
3
|
+
import { CJSOutput, ESMOutput } from "./javascript.ts";
|
|
4
|
+
import { JSONFormatter } from "./json.ts";
|
|
5
|
+
import { TypescriptFormat } from "./typescript.ts";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
export const ExportsRegistry = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ASTConfig, ASTDirectives, ASTGrammar, ASTGrammarProduction, ASTGrammarSymbol, ASTImport, ASTLexer, ASTLexerState, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateNonMatchRule, GeneratorGrammarSymbol } from "../../../typings/index.
|
|
1
|
+
import type { ASTConfig, ASTDirectives, ASTGrammar, ASTGrammarProduction, ASTGrammarSymbol, ASTImport, ASTLexer, ASTLexerState, ASTLexerStateImportRule, ASTLexerStateMatchRule, ASTLexerStateNonMatchRule, GeneratorGrammarSymbol } from "../../../typings/index.ts";
|
|
2
2
|
|
|
3
3
|
export class V2GrammarString {
|
|
4
4
|
source: string = '';
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Dictionary, GeneratorOutputOptions, GeneratorGrammarProductionRule } from "../../typings/index.
|
|
2
|
-
import { BasicGrammarTable } from "../artifacts/basic.
|
|
3
|
-
import { LexerArtifact } from "../artifacts/lexer.
|
|
4
|
-
import { LRParseTableBuilder } from "../artifacts/lr.
|
|
5
|
-
import { GeneratorState } from "../state.
|
|
6
|
-
import { CommonGenerator } from "./common.
|
|
1
|
+
import type { Dictionary, GeneratorOutputOptions, GeneratorGrammarProductionRule } from "../../typings/index.ts";
|
|
2
|
+
import { BasicGrammarTable } from "../artifacts/basic.ts";
|
|
3
|
+
import { LexerArtifact } from "../artifacts/lexer.ts";
|
|
4
|
+
import { LRParseTableBuilder } from "../artifacts/lr.ts";
|
|
5
|
+
import { GeneratorState } from "../state.ts";
|
|
6
|
+
import { CommonGenerator } from "./common.ts";
|
|
7
7
|
|
|
8
8
|
const PostProcessors = {
|
|
9
9
|
"join": "({data}) => data.join('')",
|
|
@@ -13,8 +13,12 @@ const PostProcessors = {
|
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export class JavaScriptGenerator {
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
public state: GeneratorState;
|
|
17
|
+
public options: GeneratorOutputOptions;
|
|
18
|
+
constructor(state: GeneratorState, options: GeneratorOutputOptions) {
|
|
19
|
+
this.state = state;
|
|
20
|
+
this.options = options;
|
|
21
|
+
}
|
|
18
22
|
|
|
19
23
|
name() {
|
|
20
24
|
return this.options.name || 'GWLanguage';
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './generator/generator.
|
|
2
|
-
export * from './generator/import-resolvers/auto.
|
|
3
|
-
export { StatefulLexer } from './lexers/stateful-lexer.
|
|
4
|
-
export * from './parser/parse.
|
|
5
|
-
export * from './utility/parsing.
|
|
6
|
-
export * from './typings/index.
|
|
7
|
-
export * from './utility/index.
|
|
1
|
+
export * from './generator/generator.ts';
|
|
2
|
+
export * from './generator/import-resolvers/auto.ts';
|
|
3
|
+
export { StatefulLexer } from './lexers/stateful-lexer.ts';
|
|
4
|
+
export * from './parser/parse.ts';
|
|
5
|
+
export * from './utility/parsing.ts';
|
|
6
|
+
export * from './typings/index.ts';
|
|
7
|
+
export * from './utility/index.ts';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RuntimeLexerStateMatchRule, ASTLexerStateNonMatchRule, RuntimeLexer, RuntimeLexerConfig, StatefulLexerStateDefinition } from "../typings/index.
|
|
1
|
+
import type { RuntimeLexerStateMatchRule, ASTLexerStateNonMatchRule, RuntimeLexer, RuntimeLexerConfig, StatefulLexerStateDefinition } from "../typings/index.ts";
|
|
2
2
|
|
|
3
3
|
export class StatefulLexer implements RuntimeLexer {
|
|
4
4
|
private start: string;
|