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,18 +0,0 @@
|
|
|
1
|
-
import { Generator } from "../generator/generator";
|
|
2
|
-
|
|
3
|
-
export function TypescriptFormat(generator: Generator, exportName: string) {
|
|
4
|
-
return `// Generated automatically by Grammar-Well, version ${generator.state.version}
|
|
5
|
-
// https://github.com/0x6563/grammar-well
|
|
6
|
-
import type { LanguageDefinition } from 'grammar-well';
|
|
7
|
-
|
|
8
|
-
${generator.serializeHead()}
|
|
9
|
-
|
|
10
|
-
function ${exportName}(): LanguageDefinition {
|
|
11
|
-
${generator.serializeBody()}
|
|
12
|
-
return ${generator.serializeLanguage(1)}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default ${exportName};
|
|
16
|
-
|
|
17
|
-
`;
|
|
18
|
-
}
|
package/src/parser/parser.ts
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { CharacterLexer } from "../lexers/character-lexer";
|
|
2
|
-
import { StatefulLexer } from "../lexers/stateful-lexer";
|
|
3
|
-
import { TokenBuffer } from "../lexers/token-buffer";
|
|
4
|
-
import { GrammarRule, GrammarRuleSymbol, LanguageDefinition, LexerToken, ParserAlgorithm } from "../typings";
|
|
5
|
-
import { CYK } from "./algorithms/cyk";
|
|
6
|
-
import { Earley } from "./algorithms/earley";
|
|
7
|
-
import { LRK } from "./algorithms/lrk/algorithm";
|
|
8
|
-
|
|
9
|
-
const ParserRegistry: { [key: string]: ParserAlgorithm } = {
|
|
10
|
-
earley: Earley,
|
|
11
|
-
cyk: CYK,
|
|
12
|
-
lr0: LRK
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function Parse(language: LanguageDefinition, input: string, options?: ParserOptions) {
|
|
16
|
-
const i = new Parser(language, options);
|
|
17
|
-
return i.run(input);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export class Parser {
|
|
21
|
-
|
|
22
|
-
constructor(private language: LanguageDefinition, private options: ParserOptions = { algorithm: 'earley', parserOptions: {} }) { }
|
|
23
|
-
|
|
24
|
-
run(input: string): { results: any[] } {
|
|
25
|
-
const tokenQueue = this.getTokenQueue();
|
|
26
|
-
tokenQueue.feed(input);
|
|
27
|
-
if (typeof this.options.algorithm == 'function')
|
|
28
|
-
return this.options.algorithm({ ...this.language, tokens: tokenQueue, utility: ParserUtility }, this.options.parserOptions);
|
|
29
|
-
return ParserRegistry[this.options.algorithm]({ ...this.language, tokens: tokenQueue, utility: ParserUtility }, this.options.parserOptions);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
private getTokenQueue() {
|
|
33
|
-
const { lexer } = this.language;
|
|
34
|
-
if (!lexer) {
|
|
35
|
-
return new TokenBuffer(new CharacterLexer());
|
|
36
|
-
} else if ("feed" in lexer && typeof lexer.feed == 'function') {
|
|
37
|
-
return new TokenBuffer(lexer);
|
|
38
|
-
} else if ('states' in lexer) {
|
|
39
|
-
return new TokenBuffer(new StatefulLexer(lexer));
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
export abstract class ParserUtility {
|
|
46
|
-
|
|
47
|
-
static SymbolMatchesToken(symbol: GrammarRuleSymbol, token: LexerToken) {
|
|
48
|
-
if (typeof symbol === 'string')
|
|
49
|
-
throw 'Attempted to match token against non-terminal';
|
|
50
|
-
if (typeof symbol == 'function')
|
|
51
|
-
return symbol(token);
|
|
52
|
-
if (!symbol)
|
|
53
|
-
return
|
|
54
|
-
if ("test" in symbol)
|
|
55
|
-
return symbol.test(token.value);
|
|
56
|
-
if ("token" in symbol)
|
|
57
|
-
return symbol.token === token.type || token.tag?.has(symbol.token);
|
|
58
|
-
if ("literal" in symbol)
|
|
59
|
-
return symbol.literal === token.value;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static SymbolIsTerminal(symbol: GrammarRuleSymbol) {
|
|
63
|
-
return typeof symbol != 'string';
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static PostProcess(rule: GrammarRule, data: any, meta?: any) {
|
|
67
|
-
if (rule.postprocess) {
|
|
68
|
-
return rule.postprocess({ rule, data, meta });
|
|
69
|
-
}
|
|
70
|
-
return data;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
interface ParserOptions {
|
|
75
|
-
algorithm: (keyof typeof ParserRegistry) | ParserAlgorithm,
|
|
76
|
-
parserOptions?: any;
|
|
77
|
-
}
|
package/src/typings.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import { TokenBuffer } from "./lexers/token-buffer";
|
|
2
|
-
import { ParserUtility } from "./parser/parser";
|
|
3
|
-
|
|
4
|
-
export interface Dictionary<T> {
|
|
5
|
-
[key: string]: T;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export interface CompileOptions {
|
|
9
|
-
version?: string;
|
|
10
|
-
noscript?: boolean;
|
|
11
|
-
basedir?: string;
|
|
12
|
-
resolver?: ImportResolverConstructor;
|
|
13
|
-
resolverInstance?: ImportResolver;
|
|
14
|
-
exportName?: string;
|
|
15
|
-
template?: TemplateFormat;
|
|
16
|
-
overrides?: Dictionary<string>;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export type TemplateFormat = '_default' | 'object' | 'json' | 'js' | 'javascript' | 'module' | 'esmodule' | 'esm' | 'ts' | 'typescript'
|
|
20
|
-
|
|
21
|
-
export interface GrammarBuilderContext {
|
|
22
|
-
alreadyCompiled: Set<string>;
|
|
23
|
-
resolver: ImportResolver;
|
|
24
|
-
uuids: Dictionary<number>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
export interface ImportResolver {
|
|
29
|
-
path(path: string): string;
|
|
30
|
-
body(path: string): Promise<string>;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface ImportResolverConstructor {
|
|
34
|
-
new(basePath: string): ImportResolver;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export type PostProcessor = (payload: PostProcessorPayload) => any;
|
|
38
|
-
|
|
39
|
-
interface PostProcessorPayload {
|
|
40
|
-
data: any[];
|
|
41
|
-
rule: GrammarRule;
|
|
42
|
-
meta: any;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export type JavascriptDirective = { body: GrammarTypeJS; } | { head: GrammarTypeJS }
|
|
46
|
-
|
|
47
|
-
export interface ImportDirective {
|
|
48
|
-
import: string;
|
|
49
|
-
path?: boolean;
|
|
50
|
-
alias?: string;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export interface ConfigDirective {
|
|
54
|
-
config: Dictionary<any>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export interface GrammarDirective {
|
|
58
|
-
grammar: {
|
|
59
|
-
config?: Dictionary<any>;
|
|
60
|
-
rules: GrammarBuilderRule[];
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export interface LexerDirective {
|
|
65
|
-
lexer: {
|
|
66
|
-
start?: string,
|
|
67
|
-
states: LexerStateDefinition[];
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export interface GrammarBuilderRule {
|
|
72
|
-
name: string;
|
|
73
|
-
expressions: GrammarBuilderExpression[];
|
|
74
|
-
postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export interface GrammarBuilderExpression {
|
|
78
|
-
symbols: GrammarBuilderSymbol[];
|
|
79
|
-
postprocess?: GrammarTypeJS | GrammarTypeBuiltIn | GrammarTypeTemplate;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export type GrammarBuilderSymbol = GrammarTypeRule | GrammarTypeRegex | GrammarTypeToken | GrammarTypeLiteral | GrammarBuilderSymbolRepeat | GrammarBuilderSymbolSubexpression;
|
|
83
|
-
|
|
84
|
-
export interface GrammarBuilderSymbolSubexpression {
|
|
85
|
-
subexpression: GrammarBuilderExpression[];
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
export interface GrammarBuilderSymbolRepeat {
|
|
89
|
-
expression: GrammarBuilderSymbol;
|
|
90
|
-
repeat: "+" | "*" | "?";
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export interface GrammarTypeRule {
|
|
94
|
-
rule: string;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export interface GrammarTypeRegex {
|
|
98
|
-
regex: string;
|
|
99
|
-
flags?: string
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export interface GrammarTypeToken {
|
|
103
|
-
token: string;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export interface GrammarTypeLiteral {
|
|
107
|
-
literal: string;
|
|
108
|
-
insensitive?: boolean;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export type GrammarTypeBuiltIn = { builtin: string };
|
|
112
|
-
export type GrammarTypeTemplate = { template: string };
|
|
113
|
-
export type GrammarTypeJS = { js: string };
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
export type ParserAlgorithm = ((language: LanguageDefinition & { tokens: TokenBuffer; utility: ParserUtility }, options?: any) => { results: any[], info?: any });
|
|
117
|
-
|
|
118
|
-
export type LanguageDirective = (JavascriptDirective | ImportDirective | ConfigDirective | GrammarDirective | LexerDirective);
|
|
119
|
-
|
|
120
|
-
type GrammarRuleSymbolFunction = (data: LexerToken) => boolean;
|
|
121
|
-
|
|
122
|
-
export interface GrammarRule {
|
|
123
|
-
name: string;
|
|
124
|
-
symbols: GrammarRuleSymbol[];
|
|
125
|
-
postprocess?: PostProcessor;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export type GrammarRuleSymbol = string | RegExp | GrammarTypeLiteral | GrammarTypeToken | GrammarRuleSymbolFunction;
|
|
129
|
-
|
|
130
|
-
export interface GeneratorGrammarRule {
|
|
131
|
-
name: string;
|
|
132
|
-
symbols: GeneratorGrammarSymbol[];
|
|
133
|
-
postprocess?: GrammarTypeTemplate | GrammarTypeBuiltIn | GrammarTypeJS;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export type GeneratorGrammarSymbol = { alias?: string } & (GrammarTypeRule | GrammarTypeRegex | GrammarTypeLiteral | GrammarTypeToken);
|
|
137
|
-
|
|
138
|
-
export interface LanguageDefinition {
|
|
139
|
-
lexer?: Lexer | LexerConfig;
|
|
140
|
-
grammar: {
|
|
141
|
-
start: string;
|
|
142
|
-
rules: Dictionary<GrammarRule[]>;
|
|
143
|
-
}
|
|
144
|
-
lr?: {
|
|
145
|
-
k: number;
|
|
146
|
-
table: Dictionary<LRState>;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export interface LRState {
|
|
152
|
-
actions: Next[];
|
|
153
|
-
goto: { [key: string]: string };
|
|
154
|
-
reduce?: GrammarRule;
|
|
155
|
-
isFinal: boolean;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
type Next = { symbol: GrammarRuleSymbol, next: string };
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
export interface TQRestorePoint {
|
|
162
|
-
historyIndex: number;
|
|
163
|
-
offset: number;
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export interface Lexer {
|
|
167
|
-
next(): LexerToken | undefined;
|
|
168
|
-
feed(chunk?: string, state?: ReturnType<Lexer['state']>): void;
|
|
169
|
-
state(): any;
|
|
170
|
-
flush?(): void;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export interface LexerToken {
|
|
174
|
-
type?: string | undefined;
|
|
175
|
-
tag?: Set<string>;
|
|
176
|
-
value: string;
|
|
177
|
-
offset: number;
|
|
178
|
-
line: number;
|
|
179
|
-
column: number;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export interface LexerStatus {
|
|
183
|
-
index: number;
|
|
184
|
-
line: number;
|
|
185
|
-
column: number;
|
|
186
|
-
state: string;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export interface LexerStateDefinition {
|
|
190
|
-
name: string;
|
|
191
|
-
unmatched?: string;
|
|
192
|
-
default?: string;
|
|
193
|
-
rules: (LexerStateImportRule | LexerStateMatchRule)[];
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
export interface LexerStateImportRule {
|
|
197
|
-
import: string[]
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export interface LexerStateMatchRule {
|
|
201
|
-
when: string | RegExp
|
|
202
|
-
type?: string;
|
|
203
|
-
tag?: string[];
|
|
204
|
-
pop?: number | 'all';
|
|
205
|
-
before?: boolean;
|
|
206
|
-
highlight?: string;
|
|
207
|
-
open?: string;
|
|
208
|
-
close?: string;
|
|
209
|
-
embed?: string;
|
|
210
|
-
unembed?: boolean;
|
|
211
|
-
inset?: number;
|
|
212
|
-
goto?: string;
|
|
213
|
-
set?: string;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export interface ResolvedStateDefinition {
|
|
217
|
-
name: string;
|
|
218
|
-
unmatched?: string;
|
|
219
|
-
rules: LexerStateMatchRule[];
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export interface CompiledStateDefinition {
|
|
223
|
-
regexp: RegExp;
|
|
224
|
-
unmatched?: LexerStateMatchRule;
|
|
225
|
-
rules: LexerStateMatchRule[];
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export interface LexerConfig {
|
|
229
|
-
start?: string
|
|
230
|
-
states: Dictionary<LexerStateDefinition>;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
export interface GeneratorState {
|
|
234
|
-
version: string;
|
|
235
|
-
config: Dictionary<string>;
|
|
236
|
-
head: string[];
|
|
237
|
-
body: string[];
|
|
238
|
-
lexer?: LexerConfig;
|
|
239
|
-
grammar: {
|
|
240
|
-
start: string;
|
|
241
|
-
config: {
|
|
242
|
-
postprocessorDefault?: GrammarTypeJS | GrammarTypeTemplate;
|
|
243
|
-
postprocessorOverride?: GrammarTypeJS | GrammarTypeTemplate;
|
|
244
|
-
}
|
|
245
|
-
rules: Dictionary<GeneratorGrammarRule[]>,
|
|
246
|
-
uuids: { [key: string]: number }
|
|
247
|
-
}
|
|
248
|
-
}
|
package/testing.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { readFileSync, writeFileSync } from 'fs';
|
|
2
|
-
import { AsyncRun, BuildTest } from './tests/system/testbed';
|
|
3
|
-
(async () => {
|
|
4
|
-
const options: any = {};
|
|
5
|
-
const grammar = Read('./tests/samples/grammars/lr.gwell');
|
|
6
|
-
const input = "aabb";
|
|
7
|
-
options.algorithm = 'lr0';
|
|
8
|
-
const execution = await AsyncRun(() => BuildTest(grammar, input, options));
|
|
9
|
-
console.log(execution);
|
|
10
|
-
|
|
11
|
-
})()
|
|
12
|
-
|
|
13
|
-
function Read(path) {
|
|
14
|
-
return readFileSync(path, 'utf-8');
|
|
15
|
-
}
|
|
16
|
-
function Write(path, body) {
|
|
17
|
-
return writeFileSync(path, typeof body == 'string' ? body : JSON.stringify(body, null, 2), 'utf-8');
|
|
18
|
-
}
|