@traqula/core 0.0.17 → 0.0.18
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/README.md +51 -3
- package/lib/generator-builder/generatorTypes.d.ts +47 -1
- package/lib/generator-builder/generatorTypes.js.map +1 -1
- package/lib/index.cjs +1 -1
- package/lib/indirection-builder/helpers.d.ts +7 -1
- package/lib/indirection-builder/helpers.js.map +1 -1
- package/lib/parser-builder/dynamicParser.js +1 -1
- package/lib/parser-builder/dynamicParser.js.map +1 -1
- package/lib/parser-builder/parserBuilder.js +1 -0
- package/lib/parser-builder/parserBuilder.js.map +1 -1
- package/lib/parser-builder/ruleDefTypes.d.ts +6 -0
- package/lib/parser-builder/ruleDefTypes.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -51,9 +51,9 @@ Creating a builder is as easy as:
|
|
|
51
51
|
const sparql11Tokens = LexerBuilder.create(<const> [select, describe]);
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
A new lexer can be created from an existing one by calling:
|
|
54
|
+
A new lexer can be created from an existing one, and altered by calling:
|
|
55
55
|
```typescript
|
|
56
|
-
const sparql11AdjustTokens = sparql11Tokens.addBefore(select, BuiltInAdjust);
|
|
56
|
+
const sparql11AdjustTokens = LexerBuilder.create(sparql11Tokens).addBefore(select, BuiltInAdjust);
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
### Parser Builder
|
|
@@ -96,6 +96,22 @@ Rules can be [parameterized](https://chevrotain.io/docs/features/parameterized_r
|
|
|
96
96
|
Personally I create a function that can be used to create multiple `ParserRule` objects.
|
|
97
97
|
The result of a rule should match the type provided in the `ParserRule` definition, and is the result of a call of `SUBRULE` with that rule.
|
|
98
98
|
|
|
99
|
+
##### Testing the correctness of your parser
|
|
100
|
+
By default, the parser builder will construct a parser that does not perform validation (to be more speedy).
|
|
101
|
+
When creating a parser, you best enable the validation by passing a context to the parser builder like:
|
|
102
|
+
```typescript
|
|
103
|
+
const context = {
|
|
104
|
+
tokenVocabulary: myLexerVoc,
|
|
105
|
+
lexerConfig: {
|
|
106
|
+
skipValidations: false,
|
|
107
|
+
ensureOptimizations: true,
|
|
108
|
+
},
|
|
109
|
+
parserConfig: {
|
|
110
|
+
skipValidations: false,
|
|
111
|
+
},
|
|
112
|
+
}
|
|
113
|
+
```
|
|
114
|
+
|
|
99
115
|
#### Patching rules
|
|
100
116
|
|
|
101
117
|
When a rule definition calls to a subrule using `SUBRULE(mySub)`, the implementation itself is not necessarily called.
|
|
@@ -133,6 +149,38 @@ The idea is that GeneratorRules and ParserRules can be tied together in the same
|
|
|
133
149
|
*/
|
|
134
150
|
export const iri: GeneratorRule<'iri', IriTerm> = <const> {
|
|
135
151
|
name: 'iri',
|
|
136
|
-
gImpl: () => ast => ast.value,
|
|
152
|
+
gImpl: ({ PRINT }) => ast => { PRINT(ast.value) },
|
|
137
153
|
};
|
|
138
154
|
```
|
|
155
|
+
|
|
156
|
+
While implementing a generator, you can easily support pretty print indentation manipulating `traqulaIndentation` context item.
|
|
157
|
+
The key for this context item can be accessed like:
|
|
158
|
+
```typescript
|
|
159
|
+
import { traqulaIndentation } from '@traqula/core';
|
|
160
|
+
C[traqulaIndentation] += 2;
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### A word on round tripping:
|
|
164
|
+
|
|
165
|
+
The generator builder can significantly help you with creating a round tripping parser.
|
|
166
|
+
Basically what that allows you to do is to keep information that the AST finds 'unimportant' within the generated string.
|
|
167
|
+
Take for example capitalization and spaces in the sparql spec.
|
|
168
|
+
Both are ignored in the AST, but if you want to generate the same string out of your AST, yuo need to store them somewhere.
|
|
169
|
+
Traqula helps you store this information using it's `Node` `Localization`.
|
|
170
|
+
|
|
171
|
+
Localization basically allows you to remember what _portion of the original string_ a node represents.
|
|
172
|
+
Take for example the `SENTENCE`: `I Love Traqula`, If we ignore spaces and caps in the ast, a valid representation would be:
|
|
173
|
+
```
|
|
174
|
+
SENTENCE-node{ words: [ WORD-node{ value: "i" }, WORD-node{ value: "love" }, WORD-node{ value: "traqula" } ] }
|
|
175
|
+
```
|
|
176
|
+
If we generated we would loe the capitalisation and get: `i love traqula` for example.
|
|
177
|
+
Round tripping will add a `source localization` for each node,
|
|
178
|
+
we therefore register that our SENTENCE starts at 0 and ends at 19, while our words have ranges 0-1, 2-6, 12-19.
|
|
179
|
+
Using this information our generator can reconstruct the original string (given the original string).
|
|
180
|
+
The magic happens when we start manipulating the words, so imagine we want to lowercase the word 'Love',
|
|
181
|
+
we would simply annotate in the `localization` that the node should be generated (and not reconstructed),
|
|
182
|
+
and we can generate the sentence: `I love Traqula`.
|
|
183
|
+
|
|
184
|
+
To support this feature, the generator requires that your AST follows a tree structure with respect to the ranges.
|
|
185
|
+
That means that a node cannot start later, or end earlier than its children.
|
|
186
|
+
In our example: A sentence cannot start after the first word start, nor can it end before the last word ends.
|
|
@@ -26,12 +26,58 @@ ParamType extends any[] = any[]> = {
|
|
|
26
26
|
gImpl: (def: RuleDefArg) => (ast: AstType, context: Context, ...params: ParamType) => void;
|
|
27
27
|
};
|
|
28
28
|
export interface RuleDefArg {
|
|
29
|
-
|
|
29
|
+
/**
|
|
30
|
+
* Call another generator rule so it can generate its string representation.
|
|
31
|
+
* @param rule the rule to be called
|
|
32
|
+
* @param input the ast input to work on
|
|
33
|
+
* @param arg the remaining parameters required by this rule.
|
|
34
|
+
* @constructor
|
|
35
|
+
*/
|
|
36
|
+
SUBRULE: <T, U extends any[]>(rule: GeneratorRule<any, any, T, U>, input: T, ...arg: U) => void;
|
|
37
|
+
/**
|
|
38
|
+
* Print the characters to the output string
|
|
39
|
+
* @param args arguments to be printed
|
|
40
|
+
* @constructor
|
|
41
|
+
*/
|
|
30
42
|
PRINT: (...args: string[]) => void;
|
|
43
|
+
/**
|
|
44
|
+
* Print the character to the output stream ensuring there is a space to the left oif what you print.
|
|
45
|
+
* If a space was printed right before this, it will not print a space.
|
|
46
|
+
* @param args
|
|
47
|
+
* @constructor
|
|
48
|
+
*/
|
|
31
49
|
PRINT_SPACE_LEFT: (...args: string[]) => void;
|
|
50
|
+
/**
|
|
51
|
+
* Prints all arguments as one word, ensuring it has a space before and behind each word
|
|
52
|
+
* @param args
|
|
53
|
+
* @constructor
|
|
54
|
+
*/
|
|
32
55
|
PRINT_WORD: (...args: string[]) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Prints all arguments as words, ensuring they all have a space before and behind them.
|
|
58
|
+
* @param args
|
|
59
|
+
* @constructor
|
|
60
|
+
*/
|
|
33
61
|
PRINT_WORDS: (...args: string[]) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Ensures that what you print is on a newline with the indentation equal to the indentation currently setup.
|
|
64
|
+
* @param args
|
|
65
|
+
* @constructor
|
|
66
|
+
*/
|
|
34
67
|
PRINT_ON_EMPTY: (...args: string[]) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Handles the location of a node as if it was generated using a SUBRULE.
|
|
70
|
+
* Can be used to generate many nodes within a single subrule call while still having correct localization handling.
|
|
71
|
+
* @param loc
|
|
72
|
+
* @param nodeHandle
|
|
73
|
+
* @constructor
|
|
74
|
+
*/
|
|
35
75
|
HANDLE_LOC: <T>(loc: Localized, nodeHandle: () => T) => T | undefined;
|
|
76
|
+
/**
|
|
77
|
+
* Catchup the string until a given length,
|
|
78
|
+
* printing everything from the current catchup location until the index you provide.
|
|
79
|
+
* @param until
|
|
80
|
+
* @constructor
|
|
81
|
+
*/
|
|
36
82
|
CATCHUP: (until: number) => void;
|
|
37
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generatorTypes.js","sourceRoot":"","sources":["generatorTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { Localized } from '../nodeTypings.js';\n\n/**\n * Type used to declare generator rules.\n */\nexport type GeneratorRule<\n /**\n * Context object available in rule implementation.\n */\n Context = any,\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that of the AST that we will generate the string for.\n * This type will be the provided when calling SUBRULE with this generator rule.\n * Generation happens on a per AST node basis.\n * The core will implement the generation as such. If this ever changes, we will cross that bridge when we get there.\n */\n AstType = any,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType extends any[] = any[],\n> = {\n name: NameType;\n gImpl: (def: RuleDefArg) =>\n (ast: AstType, context: Context, ...params: ParamType) => void;\n};\n\nexport interface RuleDefArg {\n SUBRULE: <T, U extends any[]>(
|
|
1
|
+
{"version":3,"file":"generatorTypes.js","sourceRoot":"","sources":["generatorTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type { Localized } from '../nodeTypings.js';\n\n/**\n * Type used to declare generator rules.\n */\nexport type GeneratorRule<\n /**\n * Context object available in rule implementation.\n */\n Context = any,\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that of the AST that we will generate the string for.\n * This type will be the provided when calling SUBRULE with this generator rule.\n * Generation happens on a per AST node basis.\n * The core will implement the generation as such. If this ever changes, we will cross that bridge when we get there.\n */\n AstType = any,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType extends any[] = any[],\n> = {\n name: NameType;\n gImpl: (def: RuleDefArg) =>\n (ast: AstType, context: Context, ...params: ParamType) => void;\n};\n\nexport interface RuleDefArg {\n /**\n * Call another generator rule so it can generate its string representation.\n * @param rule the rule to be called\n * @param input the ast input to work on\n * @param arg the remaining parameters required by this rule.\n * @constructor\n */\n SUBRULE: <T, U extends any[]>(rule: GeneratorRule<any, any, T, U>, input: T, ...arg: U) => void;\n /**\n * Print the characters to the output string\n * @param args arguments to be printed\n * @constructor\n */\n PRINT: (...args: string[]) => void;\n /**\n * Print the character to the output stream ensuring there is a space to the left oif what you print.\n * If a space was printed right before this, it will not print a space.\n * @param args\n * @constructor\n */\n PRINT_SPACE_LEFT: (...args: string[]) => void;\n /**\n * Prints all arguments as one word, ensuring it has a space before and behind each word\n * @param args\n * @constructor\n */\n PRINT_WORD: (...args: string[]) => void;\n /**\n * Prints all arguments as words, ensuring they all have a space before and behind them.\n * @param args\n * @constructor\n */\n PRINT_WORDS: (...args: string[]) => void;\n /**\n * Ensures that what you print is on a newline with the indentation equal to the indentation currently setup.\n * @param args\n * @constructor\n */\n PRINT_ON_EMPTY: (...args: string[]) => void;\n /**\n * Handles the location of a node as if it was generated using a SUBRULE.\n * Can be used to generate many nodes within a single subrule call while still having correct localization handling.\n * @param loc\n * @param nodeHandle\n * @constructor\n */\n HANDLE_LOC: <T>(loc: Localized, nodeHandle: () => T) => T | undefined;\n /**\n * Catchup the string until a given length,\n * printing everything from the current catchup location until the index you provide.\n * @param until\n * @constructor\n */\n CATCHUP: (until: number) => void;\n}\n"]}
|
package/lib/index.cjs
CHANGED
|
@@ -9840,7 +9840,7 @@ var DynamicParser = class extends EmbeddedActionsParser {
|
|
|
9840
9840
|
constructor(rules, tokenVocabulary, config = {}) {
|
|
9841
9841
|
super(tokenVocabulary, {
|
|
9842
9842
|
// RecoveryEnabled: true,
|
|
9843
|
-
maxLookahead:
|
|
9843
|
+
maxLookahead: 1,
|
|
9844
9844
|
skipValidations: true,
|
|
9845
9845
|
...config
|
|
9846
9846
|
});
|
|
@@ -4,7 +4,13 @@ export type IndirDef<Context = any, NameType extends string = string, ReturnType
|
|
|
4
4
|
fun: (def: IndirDefArg) => (c: Context, ...params: ParamType) => ReturnType;
|
|
5
5
|
};
|
|
6
6
|
export type IndirDefArg = {
|
|
7
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Calls another rule using the provided arguments.
|
|
9
|
+
* @param rule
|
|
10
|
+
* @param arg
|
|
11
|
+
* @constructor
|
|
12
|
+
*/
|
|
13
|
+
SUBRULE: <T, U extends any[]>(rule: IndirDef<any, any, T, U>, ...arg: U) => T;
|
|
8
14
|
};
|
|
9
15
|
export type IndirectionMap<RuleNames extends string> = {
|
|
10
16
|
[Key in RuleNames]: IndirDef<any, Key>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["helpers.ts"],"names":[],"mappings":"AAwBA;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAgC,KAAQ;IAC1E,MAAM,QAAQ,GAA6B,EAAE,CAAC;IAC9C,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,OAA+B,QAAQ,CAAC;AAC1C,CAAC","sourcesContent":["import type { ParseNamesFromList } from '../parser-builder/builderTypes.js';\n\nexport type IndirDef<\n Context = any,\n NameType extends string = string,\n ReturnType = unknown,\n ParamType extends any[] = any[],\n> = {\n name: NameType;\n fun: (def: IndirDefArg) => (c: Context, ...params: ParamType) => ReturnType;\n};\n\nexport type IndirDefArg = {\n /**\n * Calls another rule using the provided arguments.\n * @param rule\n * @param arg\n * @constructor\n */\n SUBRULE: <T, U extends any[]>(rule: IndirDef<any, any, T, U>, ...arg: U) => T;\n};\n\nexport type IndirectionMap<RuleNames extends string> = {[Key in RuleNames]: IndirDef<any, Key> };\n\n/**\n * Converts a list of ruledefs to a record mapping a name to the corresponding ruledef.\n */\nexport function listToIndirectionMap<T extends readonly IndirDef[]>(rules: T): ParseIndirsToObject<T> {\n const newRules: Record<string, IndirDef> = {};\n for (const rule of rules) {\n newRules[rule.name] = rule;\n }\n return <ParseIndirsToObject<T>>newRules;\n}\n\n/**\n * Convert a list of IndirDefs to a Record with the name of the IndirDef as the key, matching the IndirectionMap type.\n */\nexport type ParseIndirsToObject<\n T extends readonly IndirDef[],\n Names extends string = ParseNamesFromList<T>,\n Agg extends Record<string, IndirDef> = Record<never, never>,\n> = T extends readonly [infer First, ...infer Rest] ? (\n First extends IndirDef ? (\n Rest extends readonly IndirDef[] ? (\n ParseIndirsToObject<Rest, Names, {[K in keyof Agg | First['name']]: K extends First['name'] ? First : Agg[K] }>\n ) : never\n ) : never\n) : IndirectionMap<Names> & Agg;\n\nexport type IndirectObjFromIndirDefs<Context, Names extends string, RuleDefs extends IndirectionMap<Names>> = {\n [K in Names]: RuleDefs[K] extends IndirDef<Context, K, infer RET, infer ARGS> ?\n (context: Context, ...args: ARGS) => RET : never\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamicParser.js","sourceRoot":"","sources":["dynamicParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,YAAY,CAAC;AAIzE,MAAM,OAAO,aACX,SAAQ,qBAAqB;IACrB,OAAO,CAAsB;IAE9B,UAAU,CAAC,OAAgB;QAChC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACzB,CAAC;IAED,YAAmB,KAAe,EAAE,eAAgC,EAAE,SAAwB,EAAE;QAC9F,KAAK,CAAC,eAAe,EAAE;YACrB,yBAAyB;YACzB,YAAY,EAAE,CAAC;YACf,eAAe,EAAE,IAAI;YACrB,GAAG,MAAM;SACV,CAAC,CAAC;QACH,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAa;YACzB,GAAG,OAAO;YACV,KAAK,EAAE,IAAI,OAAO,EAAE;SACrB,CAAC;QAEF,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAsC,KAAK,CAAC,EAAE,CAAC;YAC7E,wEAAwE;YACxE,IAAI,CAAsB,IAAI,CAAC,IAAI,CAAC,GAAS,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;QACzF,CAAC;QACD,IAAI,CAAC,mBAAmB,EAAE,CAAC;IAC7B,CAAC;IAEO,gBAAgB;QACtB,MAAM,WAAW,GAAG,CA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,IAAI,EAAE,IAAI,CAAC,CAAC;YAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAChE,QAAQ,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACjE,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { IParserConfig } from '@chevrotain/types';\nimport { EmbeddedActionsParser, type TokenVocabulary } from 'chevrotain';\nimport type { ParseRuleMap } from './builderTypes.js';\nimport type { CstDef, ImplArgs, ParserRule } from './ruleDefTypes.js';\n\nexport class DynamicParser<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>>\n extends EmbeddedActionsParser {\n private context: Context | undefined;\n\n public setContext(context: Context): void {\n this.context = context;\n }\n\n public constructor(rules: RuleDefs, tokenVocabulary: TokenVocabulary, config: IParserConfig = {}) {\n super(tokenVocabulary, {\n // RecoveryEnabled: true,\n maxLookahead: 2,\n skipValidations: true,\n ...config,\n });\n this.context = undefined;\n const selfRef = this.constructSelfRef();\n const implArgs: ImplArgs = {\n ...selfRef,\n cache: new WeakMap(),\n };\n\n for (const rule of Object.values(<Record<string, ParserRule<Context>>>rules)) {\n // Function implementation itself - this function is called AFTER lexing\n this[<keyof (typeof this)>rule.name] = <any> this.RULE(rule.name, rule.impl(implArgs));\n }\n this.performSelfAnalysis();\n }\n\n private constructSelfRef(): CstDef {\n const subRuleImpl = (chevrotainSubrule: typeof this.SUBRULE): CstDef['SUBRULE'] =>\n ((cstDef, ...arg) =>\n chevrotainSubrule(<any> this[<keyof (typeof this)>cstDef.name], <any>{ ARGS: [ this.context, ...arg ]})\n ) satisfies CstDef['SUBRULE'];\n return {\n CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),\n CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),\n CONSUME2: (tokenType, option) => this.CONSUME2(tokenType, option),\n CONSUME3: (tokenType, option) => this.CONSUME3(tokenType, option),\n CONSUME4: (tokenType, option) => this.CONSUME4(tokenType, option),\n CONSUME5: (tokenType, option) => this.CONSUME5(tokenType, option),\n CONSUME6: (tokenType, option) => this.CONSUME6(tokenType, option),\n CONSUME7: (tokenType, option) => this.CONSUME7(tokenType, option),\n CONSUME8: (tokenType, option) => this.CONSUME8(tokenType, option),\n CONSUME9: (tokenType, option) => this.CONSUME9(tokenType, option),\n OPTION: actionORMethodDef => this.OPTION(actionORMethodDef),\n OPTION1: actionORMethodDef => this.OPTION1(actionORMethodDef),\n OPTION2: actionORMethodDef => this.OPTION2(actionORMethodDef),\n OPTION3: actionORMethodDef => this.OPTION3(actionORMethodDef),\n OPTION4: actionORMethodDef => this.OPTION4(actionORMethodDef),\n OPTION5: actionORMethodDef => this.OPTION5(actionORMethodDef),\n OPTION6: actionORMethodDef => this.OPTION6(actionORMethodDef),\n OPTION7: actionORMethodDef => this.OPTION7(actionORMethodDef),\n OPTION8: actionORMethodDef => this.OPTION8(actionORMethodDef),\n OPTION9: actionORMethodDef => this.OPTION9(actionORMethodDef),\n OR: altsOrOpts => this.OR(altsOrOpts),\n OR1: altsOrOpts => this.OR1(altsOrOpts),\n OR2: altsOrOpts => this.OR2(altsOrOpts),\n OR3: altsOrOpts => this.OR3(altsOrOpts),\n OR4: altsOrOpts => this.OR4(altsOrOpts),\n OR5: altsOrOpts => this.OR5(altsOrOpts),\n OR6: altsOrOpts => this.OR6(altsOrOpts),\n OR7: altsOrOpts => this.OR7(altsOrOpts),\n OR8: altsOrOpts => this.OR8(altsOrOpts),\n OR9: altsOrOpts => this.OR9(altsOrOpts),\n MANY: actionORMethodDef => this.MANY(actionORMethodDef),\n MANY1: actionORMethodDef => this.MANY1(actionORMethodDef),\n MANY2: actionORMethodDef => this.MANY2(actionORMethodDef),\n MANY3: actionORMethodDef => this.MANY3(actionORMethodDef),\n MANY4: actionORMethodDef => this.MANY4(actionORMethodDef),\n MANY5: actionORMethodDef => this.MANY5(actionORMethodDef),\n MANY6: actionORMethodDef => this.MANY6(actionORMethodDef),\n MANY7: actionORMethodDef => this.MANY7(actionORMethodDef),\n MANY8: actionORMethodDef => this.MANY8(actionORMethodDef),\n MANY9: actionORMethodDef => this.MANY9(actionORMethodDef),\n MANY_SEP: options => this.MANY_SEP(options),\n MANY_SEP1: options => this.MANY_SEP1(options),\n MANY_SEP2: options => this.MANY_SEP2(options),\n MANY_SEP3: options => this.MANY_SEP3(options),\n MANY_SEP4: options => this.MANY_SEP4(options),\n MANY_SEP5: options => this.MANY_SEP5(options),\n MANY_SEP6: options => this.MANY_SEP6(options),\n MANY_SEP7: options => this.MANY_SEP7(options),\n MANY_SEP8: options => this.MANY_SEP8(options),\n MANY_SEP9: options => this.MANY_SEP9(options),\n AT_LEAST_ONE: actionORMethodDef => this.AT_LEAST_ONE(actionORMethodDef),\n AT_LEAST_ONE1: actionORMethodDef => this.AT_LEAST_ONE1(actionORMethodDef),\n AT_LEAST_ONE2: actionORMethodDef => this.AT_LEAST_ONE2(actionORMethodDef),\n AT_LEAST_ONE3: actionORMethodDef => this.AT_LEAST_ONE3(actionORMethodDef),\n AT_LEAST_ONE4: actionORMethodDef => this.AT_LEAST_ONE4(actionORMethodDef),\n AT_LEAST_ONE5: actionORMethodDef => this.AT_LEAST_ONE5(actionORMethodDef),\n AT_LEAST_ONE6: actionORMethodDef => this.AT_LEAST_ONE6(actionORMethodDef),\n AT_LEAST_ONE7: actionORMethodDef => this.AT_LEAST_ONE7(actionORMethodDef),\n AT_LEAST_ONE8: actionORMethodDef => this.AT_LEAST_ONE8(actionORMethodDef),\n AT_LEAST_ONE9: actionORMethodDef => this.AT_LEAST_ONE9(actionORMethodDef),\n AT_LEAST_ONE_SEP: options => this.AT_LEAST_ONE_SEP(options),\n AT_LEAST_ONE_SEP1: options => this.AT_LEAST_ONE_SEP1(options),\n AT_LEAST_ONE_SEP2: options => this.AT_LEAST_ONE_SEP2(options),\n AT_LEAST_ONE_SEP3: options => this.AT_LEAST_ONE_SEP3(options),\n AT_LEAST_ONE_SEP4: options => this.AT_LEAST_ONE_SEP4(options),\n AT_LEAST_ONE_SEP5: options => this.AT_LEAST_ONE_SEP5(options),\n AT_LEAST_ONE_SEP6: options => this.AT_LEAST_ONE_SEP6(options),\n AT_LEAST_ONE_SEP7: options => this.AT_LEAST_ONE_SEP7(options),\n AT_LEAST_ONE_SEP8: options => this.AT_LEAST_ONE_SEP8(options),\n AT_LEAST_ONE_SEP9: options => this.AT_LEAST_ONE_SEP9(options),\n ACTION: func => this.ACTION(func),\n BACKTRACK: (cstDef, ...args) =>\n this.BACKTRACK(<any> this[<keyof (typeof this)>cstDef.name], <any>{ ARGS: args }),\n SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),\n SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),\n SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),\n SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),\n SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),\n SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),\n SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),\n SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),\n SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),\n SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args)),\n };\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dynamicParser.js","sourceRoot":"","sources":["dynamicParser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,YAAY,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AAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;SACjE,CAAC;IACJ,CAAC;CACF","sourcesContent":["import type { IParserConfig } from '@chevrotain/types';\nimport { EmbeddedActionsParser, type TokenVocabulary } from 'chevrotain';\nimport type { ParseRuleMap } from './builderTypes.js';\nimport type { CstDef, ImplArgs, ParserRule } from './ruleDefTypes.js';\n\nexport class DynamicParser<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>>\n extends EmbeddedActionsParser {\n private context: Context | undefined;\n\n public setContext(context: Context): void {\n this.context = context;\n }\n\n public constructor(rules: RuleDefs, tokenVocabulary: TokenVocabulary, config: IParserConfig = {}) {\n super(tokenVocabulary, {\n // RecoveryEnabled: true,\n maxLookahead: 1,\n skipValidations: true,\n ...config,\n });\n this.context = undefined;\n const selfRef = this.constructSelfRef();\n const implArgs: ImplArgs = {\n ...selfRef,\n cache: new WeakMap(),\n };\n\n for (const rule of Object.values(<Record<string, ParserRule<Context>>>rules)) {\n // Function implementation itself - this function is called AFTER lexing\n this[<keyof (typeof this)>rule.name] = <any> this.RULE(rule.name, rule.impl(implArgs));\n }\n this.performSelfAnalysis();\n }\n\n private constructSelfRef(): CstDef {\n const subRuleImpl = (chevrotainSubrule: typeof this.SUBRULE): CstDef['SUBRULE'] =>\n ((cstDef, ...arg) =>\n chevrotainSubrule(<any> this[<keyof (typeof this)>cstDef.name], <any>{ ARGS: [ this.context, ...arg ]})\n ) satisfies CstDef['SUBRULE'];\n return {\n CONSUME: (tokenType, option) => this.CONSUME(tokenType, option),\n CONSUME1: (tokenType, option) => this.CONSUME1(tokenType, option),\n CONSUME2: (tokenType, option) => this.CONSUME2(tokenType, option),\n CONSUME3: (tokenType, option) => this.CONSUME3(tokenType, option),\n CONSUME4: (tokenType, option) => this.CONSUME4(tokenType, option),\n CONSUME5: (tokenType, option) => this.CONSUME5(tokenType, option),\n CONSUME6: (tokenType, option) => this.CONSUME6(tokenType, option),\n CONSUME7: (tokenType, option) => this.CONSUME7(tokenType, option),\n CONSUME8: (tokenType, option) => this.CONSUME8(tokenType, option),\n CONSUME9: (tokenType, option) => this.CONSUME9(tokenType, option),\n OPTION: actionORMethodDef => this.OPTION(actionORMethodDef),\n OPTION1: actionORMethodDef => this.OPTION1(actionORMethodDef),\n OPTION2: actionORMethodDef => this.OPTION2(actionORMethodDef),\n OPTION3: actionORMethodDef => this.OPTION3(actionORMethodDef),\n OPTION4: actionORMethodDef => this.OPTION4(actionORMethodDef),\n OPTION5: actionORMethodDef => this.OPTION5(actionORMethodDef),\n OPTION6: actionORMethodDef => this.OPTION6(actionORMethodDef),\n OPTION7: actionORMethodDef => this.OPTION7(actionORMethodDef),\n OPTION8: actionORMethodDef => this.OPTION8(actionORMethodDef),\n OPTION9: actionORMethodDef => this.OPTION9(actionORMethodDef),\n OR: altsOrOpts => this.OR(altsOrOpts),\n OR1: altsOrOpts => this.OR1(altsOrOpts),\n OR2: altsOrOpts => this.OR2(altsOrOpts),\n OR3: altsOrOpts => this.OR3(altsOrOpts),\n OR4: altsOrOpts => this.OR4(altsOrOpts),\n OR5: altsOrOpts => this.OR5(altsOrOpts),\n OR6: altsOrOpts => this.OR6(altsOrOpts),\n OR7: altsOrOpts => this.OR7(altsOrOpts),\n OR8: altsOrOpts => this.OR8(altsOrOpts),\n OR9: altsOrOpts => this.OR9(altsOrOpts),\n MANY: actionORMethodDef => this.MANY(actionORMethodDef),\n MANY1: actionORMethodDef => this.MANY1(actionORMethodDef),\n MANY2: actionORMethodDef => this.MANY2(actionORMethodDef),\n MANY3: actionORMethodDef => this.MANY3(actionORMethodDef),\n MANY4: actionORMethodDef => this.MANY4(actionORMethodDef),\n MANY5: actionORMethodDef => this.MANY5(actionORMethodDef),\n MANY6: actionORMethodDef => this.MANY6(actionORMethodDef),\n MANY7: actionORMethodDef => this.MANY7(actionORMethodDef),\n MANY8: actionORMethodDef => this.MANY8(actionORMethodDef),\n MANY9: actionORMethodDef => this.MANY9(actionORMethodDef),\n MANY_SEP: options => this.MANY_SEP(options),\n MANY_SEP1: options => this.MANY_SEP1(options),\n MANY_SEP2: options => this.MANY_SEP2(options),\n MANY_SEP3: options => this.MANY_SEP3(options),\n MANY_SEP4: options => this.MANY_SEP4(options),\n MANY_SEP5: options => this.MANY_SEP5(options),\n MANY_SEP6: options => this.MANY_SEP6(options),\n MANY_SEP7: options => this.MANY_SEP7(options),\n MANY_SEP8: options => this.MANY_SEP8(options),\n MANY_SEP9: options => this.MANY_SEP9(options),\n AT_LEAST_ONE: actionORMethodDef => this.AT_LEAST_ONE(actionORMethodDef),\n AT_LEAST_ONE1: actionORMethodDef => this.AT_LEAST_ONE1(actionORMethodDef),\n AT_LEAST_ONE2: actionORMethodDef => this.AT_LEAST_ONE2(actionORMethodDef),\n AT_LEAST_ONE3: actionORMethodDef => this.AT_LEAST_ONE3(actionORMethodDef),\n AT_LEAST_ONE4: actionORMethodDef => this.AT_LEAST_ONE4(actionORMethodDef),\n AT_LEAST_ONE5: actionORMethodDef => this.AT_LEAST_ONE5(actionORMethodDef),\n AT_LEAST_ONE6: actionORMethodDef => this.AT_LEAST_ONE6(actionORMethodDef),\n AT_LEAST_ONE7: actionORMethodDef => this.AT_LEAST_ONE7(actionORMethodDef),\n AT_LEAST_ONE8: actionORMethodDef => this.AT_LEAST_ONE8(actionORMethodDef),\n AT_LEAST_ONE9: actionORMethodDef => this.AT_LEAST_ONE9(actionORMethodDef),\n AT_LEAST_ONE_SEP: options => this.AT_LEAST_ONE_SEP(options),\n AT_LEAST_ONE_SEP1: options => this.AT_LEAST_ONE_SEP1(options),\n AT_LEAST_ONE_SEP2: options => this.AT_LEAST_ONE_SEP2(options),\n AT_LEAST_ONE_SEP3: options => this.AT_LEAST_ONE_SEP3(options),\n AT_LEAST_ONE_SEP4: options => this.AT_LEAST_ONE_SEP4(options),\n AT_LEAST_ONE_SEP5: options => this.AT_LEAST_ONE_SEP5(options),\n AT_LEAST_ONE_SEP6: options => this.AT_LEAST_ONE_SEP6(options),\n AT_LEAST_ONE_SEP7: options => this.AT_LEAST_ONE_SEP7(options),\n AT_LEAST_ONE_SEP8: options => this.AT_LEAST_ONE_SEP8(options),\n AT_LEAST_ONE_SEP9: options => this.AT_LEAST_ONE_SEP9(options),\n ACTION: func => this.ACTION(func),\n BACKTRACK: (cstDef, ...args) =>\n this.BACKTRACK(<any> this[<keyof (typeof this)>cstDef.name], <any>{ ARGS: args }),\n SUBRULE: subRuleImpl((rule, args) => this.SUBRULE(rule, args)),\n SUBRULE1: subRuleImpl((rule, args) => this.SUBRULE1(rule, args)),\n SUBRULE2: subRuleImpl((rule, args) => this.SUBRULE2(rule, args)),\n SUBRULE3: subRuleImpl((rule, args) => this.SUBRULE3(rule, args)),\n SUBRULE4: subRuleImpl((rule, args) => this.SUBRULE4(rule, args)),\n SUBRULE5: subRuleImpl((rule, args) => this.SUBRULE5(rule, args)),\n SUBRULE6: subRuleImpl((rule, args) => this.SUBRULE6(rule, args)),\n SUBRULE7: subRuleImpl((rule, args) => this.SUBRULE7(rule, args)),\n SUBRULE8: subRuleImpl((rule, args) => this.SUBRULE8(rule, args)),\n SUBRULE9: subRuleImpl((rule, args) => this.SUBRULE9(rule, args)),\n };\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parserBuilder.js","sourceRoot":"","sources":["parserBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAShE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD;;GAEG;AACH,SAAS,gBAAgB,CAAkC,KAAQ;IACjE,MAAM,QAAQ,GAA+B,EAAE,CAAC;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,OAA8B,QAAQ,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,iDAAiD;AACjD,MAAM,OAAO,aAA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C;IAC1E,CAAC;IAEO,OAAO,CAAC,EAAE,eAAe,EAAE,MAAM,GAAG,EAAE,EAG7C;QAEC,OACuD,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;IAChH,CAAC;CACF","sourcesContent":["import type { ILexerConfig, IParserConfig, IRecognitionException } from '@chevrotain/types';\nimport type { TokenType, TokenVocabulary, EmbeddedActionsParser } from 'chevrotain';\nimport { LexerBuilder } from '../lexer-builder/LexerBuilder.js';\nimport type { CheckOverlap } from '../utils.js';\nimport type {\n ParseMethodsFromRules,\n ParserFromRules,\n ParseRuleMap,\n ParseRulesToObject,\n ParseNamesFromList,\n} from './builderTypes.js';\nimport { DynamicParser } from './dynamicParser.js';\nimport type { ParserRule } from './ruleDefTypes.js';\n\n/**\n * Converts a list of ruledefs to a record mapping a name to the corresponding ruledef.\n */\nfunction listToRuleDefMap<T extends readonly ParserRule[]>(rules: T): ParseRulesToObject<T> {\n const newRules: Record<string, ParserRule> = {};\n for (const rule of rules) {\n newRules[rule.name] = rule;\n }\n return <ParseRulesToObject<T>>newRules;\n}\n\n/**\n * The grammar builder. This is the core of traqula (besides using the amazing chevrotain framework).\n * Using the builder you can create a grammar + AST creator.\n * At any point in time, a parser can be constructed from the added rules.\n * Constructing a parser will cause a validation which will validate the correctness of the grammar.\n */\n// This code is wild so other code can be simple.\nexport class ParserBuilder<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> {\n /**\n * Create a builder from some initial grammar rules or an existing builder.\n * If a builder is provided, a new copy will be created.\n */\n public static create<\n Rules extends readonly ParserRule[] = readonly ParserRule[],\n Context = Rules[0] extends ParserRule<infer context> ? context : never,\n Names extends string = ParseNamesFromList<Rules>,\n RuleDefs extends ParseRuleMap<Names> = ParseRulesToObject<Rules>,\n >(\n start: Rules | ParserBuilder<Context, Names, RuleDefs>,\n ): ParserBuilder<Context, Names, RuleDefs> {\n if (start instanceof ParserBuilder) {\n return new ParserBuilder({ ...start.rules });\n }\n return <ParserBuilder<Context, Names, RuleDefs>> <unknown> new ParserBuilder(listToRuleDefMap(start));\n }\n\n private rules: RuleDefs;\n\n private constructor(startRules: RuleDefs) {\n this.rules = startRules;\n }\n\n public widenContext<NewContext extends Context>(): ParserBuilder<NewContext, Names, RuleDefs> {\n return <ParserBuilder<NewContext, Names, RuleDefs>> <unknown> this;\n }\n\n public typePatch<Patch extends {[Key in Names]?: [any] | [any, any[]]}>():\n ParserBuilder<Context, Names, {[Key in Names]: Key extends keyof Patch ? (\n Patch[Key] extends [any, any[]] ? ParserRule<Context, Key, Patch[Key][0], Patch[Key][1]> : (\n // Only one - infer yourself\n Patch[Key] extends [any] ? (\n RuleDefs[Key] extends ParserRule<any, any, any, infer Par> ?\n ParserRule<Context, Key, Patch[Key][0], Par> : never\n ) : never\n )\n ) : (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never) }> {\n return <any> this;\n }\n\n /**\n * Change the implementation of an existing grammar rule.\n */\n public patchRule<U extends Names, RET, ARGS extends any[]>(patch: ParserRule<Context, U, RET, ARGS>):\n ParserBuilder<Context, Names, {[Key in Names]: Key extends U ?\n ParserRule<Context, Key, RET, ARGS> :\n (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never)\n } > {\n const self = <ParserBuilder<Context, Names, {[Key in Names]: Key extends U ?\n ParserRule<Context, Key, RET, ARGS> : (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never) }>>\n <unknown> this;\n self.rules[patch.name] = <any> patch;\n return self;\n }\n\n /**\n * Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.\n */\n public addRuleRedundant<U extends string, RET, ARGS extends any[]>(rule: ParserRule<Context, U, RET, ARGS>):\n ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never)\n }> {\n const self = <ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never) }>>\n <unknown> this;\n const rules = <Record<string, ParserRule<Context>>> self.rules;\n if (rules[rule.name] !== undefined && rules[rule.name] !== rule) {\n throw new Error(`Rule ${rule.name} already exists in the builder`);\n }\n rules[rule.name] = rule;\n return self;\n }\n\n /**\n * Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.\n */\n public addRule<U extends string, RET, ARGS extends any[]>(\n rule: CheckOverlap<U, Names, ParserRule<Context, U, RET, ARGS>>,\n ): ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never) }> {\n return this.addRuleRedundant(rule);\n }\n\n public addMany<U extends readonly ParserRule<Context>[]>(\n ...rules: CheckOverlap<ParseNamesFromList<U>, Names, U>\n ): ParserBuilder<\n Context,\n Names | ParseNamesFromList<U>,\n {[K in Names | ParseNamesFromList<U>]:\n K extends keyof ParseRulesToObject<typeof rules> ? (\n ParseRulesToObject<typeof rules>[K] extends ParserRule<Context, K> ? ParseRulesToObject<typeof rules>[K] : never\n ) : (\n K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never\n )\n }\n > {\n this.rules = { ...this.rules, ...listToRuleDefMap(rules) };\n return <any> <unknown> this;\n }\n\n /**\n * Delete a grammar rule by its name.\n */\n public deleteRule<U extends Names>(ruleName: U):\n ParserBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never }> {\n delete this.rules[ruleName];\n return <ParserBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never }>>\n <unknown> this;\n }\n\n /**\n * Merge this grammar builder with another.\n * It is best to merge the bigger grammar with the smaller one.\n * If the two builders both have a grammar rule with the same name,\n * no error will be thrown case they map to the same ruledef object.\n * If they map to a different object, an error will be thrown.\n * To fix this problem, the overridingRules array should contain a rule with the same conflicting name,\n * this rule implementation will be used.\n */\n public merge<\n OtherNames extends string,\n OtherRules extends ParseRuleMap<OtherNames>,\n OW extends readonly ParserRule<Context>[],\n >(\n builder: ParserBuilder<Context, OtherNames, OtherRules>,\n overridingRules: OW,\n ):\n ParserBuilder<\n Context,\n Names | OtherNames | ParseNamesFromList<OW>,\n {[K in Names | OtherNames | ParseNamesFromList<OW>]:\n K extends keyof ParseRulesToObject<OW> ? (\n ParseRulesToObject<OW>[K] extends ParserRule<Context, K> ? ParseRulesToObject<OW>[K] : never\n )\n : (\n K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never)\n : K extends OtherNames ? (OtherRules[K] extends ParserRule<Context, K> ? OtherRules[K] : never) : never\n ) }\n > {\n // Assume the other grammar is bigger than yours. So start from that one and add this one\n const otherRules: Record<string, ParserRule<Context>> = { ...builder.rules };\n const myRules: Record<string, ParserRule<Context>> = this.rules;\n\n for (const rule of Object.values(myRules)) {\n if (otherRules[rule.name] === undefined) {\n otherRules[rule.name] = rule;\n } else {\n const existingRule = otherRules[rule.name];\n // If same rule, no issue, move on. Else\n if (existingRule !== rule) {\n const override = overridingRules.find(x => x.name === rule.name);\n // If override specified, take override, else, inform user that there is a conflict\n if (override) {\n otherRules[rule.name] = override;\n } else {\n throw new Error(`Rule with name \"${rule.name}\" already exists in the builder, specify an override to resolve conflict`);\n }\n }\n }\n }\n\n this.rules = <any> <unknown> otherRules;\n return <any> <unknown> this;\n }\n\n private defaultErrorHandler(input: string, errors: IRecognitionException[]): void {\n const firstError = errors[0];\n const messageBuilder: string[] = [ 'Parse error' ];\n const lineIdx = firstError.token.startLine;\n if (lineIdx !== undefined && !Number.isNaN(lineIdx)) {\n const errorLine = input.split('\\n')[lineIdx - 1];\n messageBuilder.push(` on line ${lineIdx}\n${errorLine}`);\n const columnIdx = firstError.token.startColumn;\n if (columnIdx !== undefined) {\n messageBuilder.push(`\\n${'-'.repeat(columnIdx - 1)}^`);\n }\n }\n messageBuilder.push(`\\n${firstError.message}`);\n throw new Error(messageBuilder.join(''));\n }\n\n public build({\n tokenVocabulary,\n parserConfig = {},\n lexerConfig = {},\n queryPreProcessor = s => s,\n errorHandler,\n }: {\n tokenVocabulary: readonly TokenType[];\n parserConfig?: IParserConfig;\n lexerConfig?: ILexerConfig;\n queryPreProcessor?: (input: string) => string;\n errorHandler?: (errors: IRecognitionException[]) => void;\n }): ParserFromRules<Context, Names, RuleDefs> {\n const lexer = LexerBuilder.create().add(...tokenVocabulary).build({\n positionTracking: 'full',\n recoveryEnabled: false,\n ensureOptimizations: true,\n safeMode: false,\n skipValidations: true,\n ...lexerConfig,\n });\n // Get the chevrotain parser\n const parser = this.consume({\n tokenVocabulary: <TokenType[]> tokenVocabulary,\n config: parserConfig,\n });\n // Start building a parser that does not pass input using a state, but instead gets it as a function argument.\n const selfSufficientParser: Partial<ParserFromRules<Context, Names, RuleDefs>> = {};\n\n // To do that, we need to create a wrapper for each parser rule.\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n for (const rule of <ParserRule<Context, Names>[]> Object.values(this.rules)) {\n selfSufficientParser[rule.name] = <any> ((input: string, context: Context, ...args: unknown[]) => {\n const processedInput = queryPreProcessor(input);\n const lexResult = lexer.tokenize(processedInput);\n\n // This also resets the parser\n parser.input = lexResult.tokens;\n parser.setContext(context);\n const result = parser[rule.name](context, ...args);\n if (parser.errors.length > 0) {\n if (errorHandler) {\n errorHandler(parser.errors);\n } else {\n this.defaultErrorHandler(processedInput, parser.errors);\n }\n }\n return result;\n });\n }\n return <ParserFromRules<Context, Names, RuleDefs>> selfSufficientParser;\n }\n\n private consume({ tokenVocabulary, config = {}}: {\n tokenVocabulary: TokenVocabulary;\n config?: IParserConfig;\n }): EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> &\n { setContext: (context: Context) => void } {\n return <EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> &\n { setContext: (context: Context) => void }><unknown> new DynamicParser(this.rules, tokenVocabulary, config);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"parserBuilder.js","sourceRoot":"","sources":["parserBuilder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAShE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAGnD;;GAEG;AACH,SAAS,gBAAgB,CAAkC,KAAQ;IACjE,MAAM,QAAQ,GAA+B,EAAE,CAAC;IAChD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAC7B,CAAC;IACD,OAA8B,QAAQ,CAAC;AACzC,CAAC;AAED;;;;;GAKG;AACH,iDAAiD;AACjD,MAAM,OAAO,aAAa;IACxB;;;OAGG;IACI,MAAM,CAAC,MAAM,CAMlB,KAAsD;QAEtD,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;YACnC,OAAO,IAAI,aAAa,CAAC,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;QAC/C,CAAC;QACD,OAA2D,IAAI,aAAa,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxG,CAAC;IAEO,KAAK,CAAW;IAExB,YAAoB,UAAoB;QACtC,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC;IAC1B,CAAC;IAEM,YAAY;QACjB,OAA8D,IAAI,CAAC;IACrE,CAAC;IAEM,SAAS;QAUd,OAAa,IAAI,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,SAAS,CAA2C,KAAwC;QAKjG,MAAM,IAAI,GAEE,IAAI,CAAC;QACjB,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,IAAI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MAAM,SAAS,GAAG,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;gBAEjD,8BAA8B;gBAC9B,MAAM,CAAC,KAAK,GAAG,SAAS,CAAC,MAAM,CAAC;gBAChC,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;gBAC3B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC,CAAC;gBACnD,IAAI,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;oBAC7B,0BAA0B;oBAC1B,IAAI,YAAY,EAAE,CAAC;wBACjB,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;oBAC9B,CAAC;yBAAM,CAAC;wBACN,IAAI,CAAC,mBAAmB,CAAC,cAAc,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;oBAC1D,CAAC;gBACH,CAAC;gBACD,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAmD,oBAAoB,CAAC;IAC1E,CAAC;IAEO,OAAO,CAAC,EAAE,eAAe,EAAE,MAAM,GAAG,EAAE,EAG7C;QAEC,OACuD,IAAI,aAAa,CAAC,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE,MAAM,CAAC,CAAC;IAChH,CAAC;CACF","sourcesContent":["import type { ILexerConfig, IParserConfig, IRecognitionException } from '@chevrotain/types';\nimport type { TokenType, TokenVocabulary, EmbeddedActionsParser } from 'chevrotain';\nimport { LexerBuilder } from '../lexer-builder/LexerBuilder.js';\nimport type { CheckOverlap } from '../utils.js';\nimport type {\n ParseMethodsFromRules,\n ParserFromRules,\n ParseRuleMap,\n ParseRulesToObject,\n ParseNamesFromList,\n} from './builderTypes.js';\nimport { DynamicParser } from './dynamicParser.js';\nimport type { ParserRule } from './ruleDefTypes.js';\n\n/**\n * Converts a list of ruledefs to a record mapping a name to the corresponding ruledef.\n */\nfunction listToRuleDefMap<T extends readonly ParserRule[]>(rules: T): ParseRulesToObject<T> {\n const newRules: Record<string, ParserRule> = {};\n for (const rule of rules) {\n newRules[rule.name] = rule;\n }\n return <ParseRulesToObject<T>>newRules;\n}\n\n/**\n * The grammar builder. This is the core of traqula (besides using the amazing chevrotain framework).\n * Using the builder you can create a grammar + AST creator.\n * At any point in time, a parser can be constructed from the added rules.\n * Constructing a parser will cause a validation which will validate the correctness of the grammar.\n */\n// This code is wild so other code can be simple.\nexport class ParserBuilder<Context, Names extends string, RuleDefs extends ParseRuleMap<Names>> {\n /**\n * Create a builder from some initial grammar rules or an existing builder.\n * If a builder is provided, a new copy will be created.\n */\n public static create<\n Rules extends readonly ParserRule[] = readonly ParserRule[],\n Context = Rules[0] extends ParserRule<infer context> ? context : never,\n Names extends string = ParseNamesFromList<Rules>,\n RuleDefs extends ParseRuleMap<Names> = ParseRulesToObject<Rules>,\n >(\n start: Rules | ParserBuilder<Context, Names, RuleDefs>,\n ): ParserBuilder<Context, Names, RuleDefs> {\n if (start instanceof ParserBuilder) {\n return new ParserBuilder({ ...start.rules });\n }\n return <ParserBuilder<Context, Names, RuleDefs>> <unknown> new ParserBuilder(listToRuleDefMap(start));\n }\n\n private rules: RuleDefs;\n\n private constructor(startRules: RuleDefs) {\n this.rules = startRules;\n }\n\n public widenContext<NewContext extends Context>(): ParserBuilder<NewContext, Names, RuleDefs> {\n return <ParserBuilder<NewContext, Names, RuleDefs>> <unknown> this;\n }\n\n public typePatch<Patch extends {[Key in Names]?: [any] | [any, any[]]}>():\n ParserBuilder<Context, Names, {[Key in Names]: Key extends keyof Patch ? (\n Patch[Key] extends [any, any[]] ? ParserRule<Context, Key, Patch[Key][0], Patch[Key][1]> : (\n // Only one - infer yourself\n Patch[Key] extends [any] ? (\n RuleDefs[Key] extends ParserRule<any, any, any, infer Par> ?\n ParserRule<Context, Key, Patch[Key][0], Par> : never\n ) : never\n )\n ) : (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never) }> {\n return <any> this;\n }\n\n /**\n * Change the implementation of an existing grammar rule.\n */\n public patchRule<U extends Names, RET, ARGS extends any[]>(patch: ParserRule<Context, U, RET, ARGS>):\n ParserBuilder<Context, Names, {[Key in Names]: Key extends U ?\n ParserRule<Context, Key, RET, ARGS> :\n (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never)\n } > {\n const self = <ParserBuilder<Context, Names, {[Key in Names]: Key extends U ?\n ParserRule<Context, Key, RET, ARGS> : (RuleDefs[Key] extends ParserRule<Context, Key> ? RuleDefs[Key] : never) }>>\n <unknown> this;\n self.rules[patch.name] = <any> patch;\n return self;\n }\n\n /**\n * Add a rule to the grammar. If the rule already exists, but the implementation differs, an error will be thrown.\n */\n public addRuleRedundant<U extends string, RET, ARGS extends any[]>(rule: ParserRule<Context, U, RET, ARGS>):\n ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never)\n }> {\n const self = <ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never) }>>\n <unknown> this;\n const rules = <Record<string, ParserRule<Context>>> self.rules;\n if (rules[rule.name] !== undefined && rules[rule.name] !== rule) {\n throw new Error(`Rule ${rule.name} already exists in the builder`);\n }\n rules[rule.name] = rule;\n return self;\n }\n\n /**\n * Add a rule to the grammar. Will raise a typescript error if the rule already exists in the grammar.\n */\n public addRule<U extends string, RET, ARGS extends any[]>(\n rule: CheckOverlap<U, Names, ParserRule<Context, U, RET, ARGS>>,\n ): ParserBuilder<Context, Names | U, {[K in Names | U]: K extends U ?\n ParserRule<Context, K, RET, ARGS> :\n (K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never) }> {\n return this.addRuleRedundant(rule);\n }\n\n public addMany<U extends readonly ParserRule<Context>[]>(\n ...rules: CheckOverlap<ParseNamesFromList<U>, Names, U>\n ): ParserBuilder<\n Context,\n Names | ParseNamesFromList<U>,\n {[K in Names | ParseNamesFromList<U>]:\n K extends keyof ParseRulesToObject<typeof rules> ? (\n ParseRulesToObject<typeof rules>[K] extends ParserRule<Context, K> ? ParseRulesToObject<typeof rules>[K] : never\n ) : (\n K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never) : never\n )\n }\n > {\n this.rules = { ...this.rules, ...listToRuleDefMap(rules) };\n return <any> <unknown> this;\n }\n\n /**\n * Delete a grammar rule by its name.\n */\n public deleteRule<U extends Names>(ruleName: U):\n ParserBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never }> {\n delete this.rules[ruleName];\n return <ParserBuilder<Context, Exclude<Names, U>, {[K in Exclude<Names, U>]:\n RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never }>>\n <unknown> this;\n }\n\n /**\n * Merge this grammar builder with another.\n * It is best to merge the bigger grammar with the smaller one.\n * If the two builders both have a grammar rule with the same name,\n * no error will be thrown case they map to the same ruledef object.\n * If they map to a different object, an error will be thrown.\n * To fix this problem, the overridingRules array should contain a rule with the same conflicting name,\n * this rule implementation will be used.\n */\n public merge<\n OtherNames extends string,\n OtherRules extends ParseRuleMap<OtherNames>,\n OW extends readonly ParserRule<Context>[],\n >(\n builder: ParserBuilder<Context, OtherNames, OtherRules>,\n overridingRules: OW,\n ):\n ParserBuilder<\n Context,\n Names | OtherNames | ParseNamesFromList<OW>,\n {[K in Names | OtherNames | ParseNamesFromList<OW>]:\n K extends keyof ParseRulesToObject<OW> ? (\n ParseRulesToObject<OW>[K] extends ParserRule<Context, K> ? ParseRulesToObject<OW>[K] : never\n )\n : (\n K extends Names ? (RuleDefs[K] extends ParserRule<Context, K> ? RuleDefs[K] : never)\n : K extends OtherNames ? (OtherRules[K] extends ParserRule<Context, K> ? OtherRules[K] : never) : never\n ) }\n > {\n // Assume the other grammar is bigger than yours. So start from that one and add this one\n const otherRules: Record<string, ParserRule<Context>> = { ...builder.rules };\n const myRules: Record<string, ParserRule<Context>> = this.rules;\n\n for (const rule of Object.values(myRules)) {\n if (otherRules[rule.name] === undefined) {\n otherRules[rule.name] = rule;\n } else {\n const existingRule = otherRules[rule.name];\n // If same rule, no issue, move on. Else\n if (existingRule !== rule) {\n const override = overridingRules.find(x => x.name === rule.name);\n // If override specified, take override, else, inform user that there is a conflict\n if (override) {\n otherRules[rule.name] = override;\n } else {\n throw new Error(`Rule with name \"${rule.name}\" already exists in the builder, specify an override to resolve conflict`);\n }\n }\n }\n }\n\n this.rules = <any> <unknown> otherRules;\n return <any> <unknown> this;\n }\n\n private defaultErrorHandler(input: string, errors: IRecognitionException[]): void {\n const firstError = errors[0];\n const messageBuilder: string[] = [ 'Parse error' ];\n const lineIdx = firstError.token.startLine;\n if (lineIdx !== undefined && !Number.isNaN(lineIdx)) {\n const errorLine = input.split('\\n')[lineIdx - 1];\n messageBuilder.push(` on line ${lineIdx}\n${errorLine}`);\n const columnIdx = firstError.token.startColumn;\n if (columnIdx !== undefined) {\n messageBuilder.push(`\\n${'-'.repeat(columnIdx - 1)}^`);\n }\n }\n messageBuilder.push(`\\n${firstError.message}`);\n throw new Error(messageBuilder.join(''));\n }\n\n public build({\n tokenVocabulary,\n parserConfig = {},\n lexerConfig = {},\n queryPreProcessor = s => s,\n errorHandler,\n }: {\n tokenVocabulary: readonly TokenType[];\n parserConfig?: IParserConfig;\n lexerConfig?: ILexerConfig;\n queryPreProcessor?: (input: string) => string;\n errorHandler?: (errors: IRecognitionException[]) => void;\n }): ParserFromRules<Context, Names, RuleDefs> {\n const lexer = LexerBuilder.create().add(...tokenVocabulary).build({\n positionTracking: 'full',\n recoveryEnabled: false,\n ensureOptimizations: true,\n safeMode: false,\n skipValidations: true,\n ...lexerConfig,\n });\n // Get the chevrotain parser\n const parser = this.consume({\n tokenVocabulary: <TokenType[]> tokenVocabulary,\n config: parserConfig,\n });\n // Start building a parser that does not pass input using a state, but instead gets it as a function argument.\n const selfSufficientParser: Partial<ParserFromRules<Context, Names, RuleDefs>> = {};\n\n // To do that, we need to create a wrapper for each parser rule.\n // eslint-disable-next-line ts/no-unnecessary-type-assertion\n for (const rule of <ParserRule<Context, Names>[]> Object.values(this.rules)) {\n selfSufficientParser[rule.name] = <any> ((input: string, context: Context, ...args: unknown[]) => {\n const processedInput = queryPreProcessor(input);\n const lexResult = lexer.tokenize(processedInput);\n\n // This also resets the parser\n parser.input = lexResult.tokens;\n parser.setContext(context);\n const result = parser[rule.name](context, ...args);\n if (parser.errors.length > 0) {\n // Console.log(lexResult);\n if (errorHandler) {\n errorHandler(parser.errors);\n } else {\n this.defaultErrorHandler(processedInput, parser.errors);\n }\n }\n return result;\n });\n }\n return <ParserFromRules<Context, Names, RuleDefs>> selfSufficientParser;\n }\n\n private consume({ tokenVocabulary, config = {}}: {\n tokenVocabulary: TokenVocabulary;\n config?: IParserConfig;\n }): EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> &\n { setContext: (context: Context) => void } {\n return <EmbeddedActionsParser & ParseMethodsFromRules<Context, Names, RuleDefs> &\n { setContext: (context: Context) => void }><unknown> new DynamicParser(this.rules, tokenVocabulary, config);\n }\n}\n"]}
|
|
@@ -331,6 +331,12 @@ export interface CstDef {
|
|
|
331
331
|
AT_LEAST_ONE_SEP7: (options: AtLeastOneSepMethodOpts<any>) => void;
|
|
332
332
|
AT_LEAST_ONE_SEP8: (options: AtLeastOneSepMethodOpts<any>) => void;
|
|
333
333
|
AT_LEAST_ONE_SEP9: (options: AtLeastOneSepMethodOpts<any>) => void;
|
|
334
|
+
/**
|
|
335
|
+
* Perform an action that is only executed during actual parsing and not during parser initialization.
|
|
336
|
+
* (When a lot of this secretly return null)
|
|
337
|
+
* @param impl
|
|
338
|
+
* @constructor
|
|
339
|
+
*/
|
|
334
340
|
ACTION: <T>(impl: () => T) => T;
|
|
335
341
|
BACKTRACK: BacktrackFunc;
|
|
336
342
|
SUBRULE: SubRuleFunc;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ruleDefTypes.js","sourceRoot":"","sources":["ruleDefTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AtLeastOneSepMethodOpts,\n DSLMethodOpts,\n DSLMethodOptsWithErr,\n GrammarAction,\n IOrAlt,\n ManySepMethodOpts,\n OrMethodOpts,\n} from '@chevrotain/types';\nimport type { ConsumeMethodOpts, IToken, TokenType } from 'chevrotain';\n\n/**\n * Get the return-type of a RuleDef\n */\nexport type RuleDefReturn<T extends ParserRule> = T extends ParserRule<any, string, infer Ret> ? Ret : never;\n\n/**\n * Type used to declare grammar rules.\n */\nexport type ParserRule<\n /**\n * Context object available in rule implementation.\n */\n Context = any,\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType extends any[] = any[],\n> = {\n name: NameType;\n impl: (def: ImplArgs) => (context: Context, ...params: ParamType) => ReturnType;\n};\n\n/**\n * Type expected by grammar rules in the main `impl` function.\n */\nexport interface ImplArgs extends CstDef {\n cache: WeakMap<ParserRule, unknown>;\n}\n\n/**\n * Type definition used by {@link CstDef.SUBRULE} and family.\n */\ntype SubRuleFunc = <T extends string, U = unknown, ARGS extends any[] = any>(\n cstDef: ParserRule<any, T, U, ARGS>,\n ...argument: ARGS\n) => U;\n/**\n * Type definition used by {@link CstDef.BACKTRACK}.\n */\ntype BacktrackFunc = <T extends string, U = unknown, ARGS extends any[] = any>(\n cstDef: ParserRule<any, T, U, ARGS>,\n ...argument: ARGS\n) => () => boolean;\n\n/**\n * Mainly a repetition of the functions exposed by the {@link EmbeddedActionsParser},\n * with some small adjustments that allow for the API changes made by traqula.\n * Specifically changes are made to the {@link CstDef.SUBRULE} (and family) interface,\n * and to the {@link CstDef.BACKTRACK} interface.\n */\nexport interface CstDef {\n /**\n *\n * A Parsing DSL method use to consume a single Token.\n * In EBNF terms this is equivalent to a Terminal.\n *\n * A Token will be consumed, IFF the next token in the token vector matches `tokType`.\n * otherwise the parser may attempt to perform error recovery (if enabled).\n *\n * The index in the method name indicates the unique occurrence of a terminal consumption\n * inside a the top level rule. What this means is that if a terminal appears\n * more than once in a single rule, each appearance must have a **different** index.\n *\n * For example:\n * ```\n * this.RULE(\"qualifiedName\", () => {\n * this.CONSUME1(Identifier);\n * this.MANY(() => {\n * this.CONSUME1(Dot);\n * // here we use CONSUME2 because the terminal\n * // 'Identifier' has already appeared previously in the\n * // the rule 'parseQualifiedName'\n * this.CONSUME2(Identifier);\n * });\n * })\n * ```\n *\n * - See more details on the [unique suffixes requirement](http://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES).\n *\n * @param tokType - The Type of the token to be consumed.\n * @param options - optional properties to modify the behavior of CONSUME.\n */\n CONSUME: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME1: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME2: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME3: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME4: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME5: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME6: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME7: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME8: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME9: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n /**\n * Parsing DSL Method that Indicates an Optional production.\n * in EBNF notation this is equivalent to: \"[...]\".\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.OPTION(() => {\n * this.CONSUME(Digit)}\n * );\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.OPTION({\n * GATE:predicateFunc,\n * DEF: () => {\n * this.CONSUME(Digit)\n * }});\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the optional production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke once\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n * @returns The `GrammarAction` return value (OUT) if the optional syntax is encountered\n * or `undefined` if not.\n */\n OPTION: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION1: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION2: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION3: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION4: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION5: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION6: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION7: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION8: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION9: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n /**\n * Parsing DSL method that indicates a choice between a set of alternatives must be made.\n * This is equivalent to an EBNF alternation (A | B | C | D ...), except\n * that the alternatives are ordered like in a PEG grammar.\n * This means that the **first** matching alternative is always chosen.\n *\n * There are several forms for the inner alternatives array:\n *\n * - Passing alternatives array directly:\n * ```\n * this.OR([\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Passing alternative array directly with predicates (GATE):\n * ```\n * this.OR([\n * { GATE: predicateFunc1, ALT:() => { this.CONSUME(One) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Two) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - These syntax forms can also be mixed:\n * ```\n * this.OR([\n * {\n * GATE: predicateFunc1,\n * ALT:() => { this.CONSUME(One) }\n * },\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Additionally an \"options\" object may be used:\n * ```\n * this.OR({\n * DEF:[\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ],\n * // OPTIONAL property\n * ERR_MSG: \"A Number\"\n * })\n * ```\n *\n * The 'predicateFuncX' in the long form can be used to add constraints to choosing the alternative.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the alternation production in it's top rule.\n *\n * @param altsOrOpts - A set of alternatives or an \"OPTIONS\" object describing the alternatives\n * and optional properties.\n *\n * @returns The result of invoking the chosen alternative.\n */\n OR: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR1: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR2: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR3: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR4: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR5: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR6: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR7: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR8: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR9: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more.\n * This is equivalent to EBNF repetition \\{...\\}.\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.MANY(() => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * })\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.MANY({\n * GATE: predicateFunc,\n * DEF: () => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * }\n * });\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n MANY: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more with a separator\n * Token between the repetitions.\n *\n * Example:\n *\n * ```\n * this.MANY_SEP({\n * SEP:Comma,\n * DEF: () => {\n * this.CONSUME(Number};\n * // ...\n * })\n * ```\n *\n * Note that because this DSL method always requires more than one argument the options object is always required\n * and it is not possible to use a shorter form like in the MANY DSL method.\n *\n * Note that for the purposes of deciding on whether or not another iteration exists\n * Only a single Token is examined (The separator). Therefore if the grammar being implemented is\n * so \"crazy\" to require multiple tokens to identify an item separator please use the more basic DSL methods\n * to implement it.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n */\n MANY_SEP: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP1: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP2: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP3: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP4: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP5: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP6: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP7: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP8: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP9: (options: ManySepMethodOpts<any>) => void;\n /**\n * Convenience method, same as MANY but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause a parsing error.\n *\n * @see MANY\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n AT_LEAST_ONE: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n /**\n * Convenience method, same as MANY_SEP but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause the parser to attempt error recovery.\n *\n * Note that an additional optional property ERR_MSG can be used to provide custom error messages.\n *\n * @see MANY_SEP\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n * @return ISeparatedIterationResult<OUT>\n */\n AT_LEAST_ONE_SEP: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP1: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP2: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP3: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP4: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP5: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP6: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP7: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP8: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP9: (options: AtLeastOneSepMethodOpts<any>) => void;\n ACTION: <T>(impl: () => T) => T;\n BACKTRACK: BacktrackFunc;\n SUBRULE: SubRuleFunc;\n SUBRULE1: SubRuleFunc;\n SUBRULE2: SubRuleFunc;\n SUBRULE3: SubRuleFunc;\n SUBRULE4: SubRuleFunc;\n SUBRULE5: SubRuleFunc;\n SUBRULE6: SubRuleFunc;\n SUBRULE7: SubRuleFunc;\n SUBRULE8: SubRuleFunc;\n SUBRULE9: SubRuleFunc;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ruleDefTypes.js","sourceRoot":"","sources":["ruleDefTypes.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AtLeastOneSepMethodOpts,\n DSLMethodOpts,\n DSLMethodOptsWithErr,\n GrammarAction,\n IOrAlt,\n ManySepMethodOpts,\n OrMethodOpts,\n} from '@chevrotain/types';\nimport type { ConsumeMethodOpts, IToken, TokenType } from 'chevrotain';\n\n/**\n * Get the return-type of a RuleDef\n */\nexport type RuleDefReturn<T extends ParserRule> = T extends ParserRule<any, string, infer Ret> ? Ret : never;\n\n/**\n * Type used to declare grammar rules.\n */\nexport type ParserRule<\n /**\n * Context object available in rule implementation.\n */\n Context = any,\n /**\n * Name of grammar rule, should be a strict subtype of string like 'myGrammarRule'.\n */\n NameType extends string = string,\n /**\n * Type that will be returned after a correct parse of this rule.\n * This type will be the return type of calling SUBRULE with this grammar rule.\n */\n ReturnType = unknown,\n /**\n * Function arguments that can be given to convey the state of the current parse operation.\n */\n ParamType extends any[] = any[],\n> = {\n name: NameType;\n impl: (def: ImplArgs) => (context: Context, ...params: ParamType) => ReturnType;\n};\n\n/**\n * Type expected by grammar rules in the main `impl` function.\n */\nexport interface ImplArgs extends CstDef {\n cache: WeakMap<ParserRule, unknown>;\n}\n\n/**\n * Type definition used by {@link CstDef.SUBRULE} and family.\n */\ntype SubRuleFunc = <T extends string, U = unknown, ARGS extends any[] = any>(\n cstDef: ParserRule<any, T, U, ARGS>,\n ...argument: ARGS\n) => U;\n/**\n * Type definition used by {@link CstDef.BACKTRACK}.\n */\ntype BacktrackFunc = <T extends string, U = unknown, ARGS extends any[] = any>(\n cstDef: ParserRule<any, T, U, ARGS>,\n ...argument: ARGS\n) => () => boolean;\n\n/**\n * Mainly a repetition of the functions exposed by the {@link EmbeddedActionsParser},\n * with some small adjustments that allow for the API changes made by traqula.\n * Specifically changes are made to the {@link CstDef.SUBRULE} (and family) interface,\n * and to the {@link CstDef.BACKTRACK} interface.\n */\nexport interface CstDef {\n /**\n *\n * A Parsing DSL method use to consume a single Token.\n * In EBNF terms this is equivalent to a Terminal.\n *\n * A Token will be consumed, IFF the next token in the token vector matches `tokType`.\n * otherwise the parser may attempt to perform error recovery (if enabled).\n *\n * The index in the method name indicates the unique occurrence of a terminal consumption\n * inside a the top level rule. What this means is that if a terminal appears\n * more than once in a single rule, each appearance must have a **different** index.\n *\n * For example:\n * ```\n * this.RULE(\"qualifiedName\", () => {\n * this.CONSUME1(Identifier);\n * this.MANY(() => {\n * this.CONSUME1(Dot);\n * // here we use CONSUME2 because the terminal\n * // 'Identifier' has already appeared previously in the\n * // the rule 'parseQualifiedName'\n * this.CONSUME2(Identifier);\n * });\n * })\n * ```\n *\n * - See more details on the [unique suffixes requirement](http://chevrotain.io/docs/FAQ.html#NUMERICAL_SUFFIXES).\n *\n * @param tokType - The Type of the token to be consumed.\n * @param options - optional properties to modify the behavior of CONSUME.\n */\n CONSUME: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME1: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME2: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME3: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME4: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME5: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME6: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME7: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME8: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n CONSUME9: (tokType: TokenType, options?: ConsumeMethodOpts) => IToken;\n /**\n * Parsing DSL Method that Indicates an Optional production.\n * in EBNF notation this is equivalent to: \"[...]\".\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.OPTION(() => {\n * this.CONSUME(Digit)}\n * );\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.OPTION({\n * GATE:predicateFunc,\n * DEF: () => {\n * this.CONSUME(Digit)\n * }});\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the optional production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke once\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n * @returns The `GrammarAction` return value (OUT) if the optional syntax is encountered\n * or `undefined` if not.\n */\n OPTION: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION1: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION2: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION3: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION4: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION5: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION6: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION7: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION8: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n OPTION9: <OUT>(\n actionORMethodDef: GrammarAction<OUT> | DSLMethodOpts<OUT>,\n ) => OUT | undefined;\n /**\n * Parsing DSL method that indicates a choice between a set of alternatives must be made.\n * This is equivalent to an EBNF alternation (A | B | C | D ...), except\n * that the alternatives are ordered like in a PEG grammar.\n * This means that the **first** matching alternative is always chosen.\n *\n * There are several forms for the inner alternatives array:\n *\n * - Passing alternatives array directly:\n * ```\n * this.OR([\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Passing alternative array directly with predicates (GATE):\n * ```\n * this.OR([\n * { GATE: predicateFunc1, ALT:() => { this.CONSUME(One) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Two) }},\n * { GATE: predicateFuncX, ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - These syntax forms can also be mixed:\n * ```\n * this.OR([\n * {\n * GATE: predicateFunc1,\n * ALT:() => { this.CONSUME(One) }\n * },\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ])\n * ```\n *\n * - Additionally an \"options\" object may be used:\n * ```\n * this.OR({\n * DEF:[\n * { ALT:() => { this.CONSUME(One) }},\n * { ALT:() => { this.CONSUME(Two) }},\n * { ALT:() => { this.CONSUME(Three) }}\n * ],\n * // OPTIONAL property\n * ERR_MSG: \"A Number\"\n * })\n * ```\n *\n * The 'predicateFuncX' in the long form can be used to add constraints to choosing the alternative.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the alternation production in it's top rule.\n *\n * @param altsOrOpts - A set of alternatives or an \"OPTIONS\" object describing the alternatives\n * and optional properties.\n *\n * @returns The result of invoking the chosen alternative.\n */\n OR: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR1: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR2: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR3: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR4: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR5: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR6: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR7: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR8: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n OR9: <T>(altsOrOpts: IOrAlt<T>[] | OrMethodOpts<T>) => T;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more.\n * This is equivalent to EBNF repetition \\{...\\}.\n *\n * Note that there are two syntax forms:\n * - Passing the grammar action directly:\n * ```\n * this.MANY(() => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * })\n * ```\n *\n * - using an \"options\" object:\n * ```\n * this.MANY({\n * GATE: predicateFunc,\n * DEF: () => {\n * this.CONSUME(Comma)\n * this.CONSUME(Digit)\n * }\n * });\n * ```\n *\n * The optional 'GATE' property in \"options\" object form can be used to add constraints\n * to invoking the grammar action.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n MANY: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n MANY9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOpts<any>,\n ) => void;\n /**\n * Parsing DSL method, that indicates a repetition of zero or more with a separator\n * Token between the repetitions.\n *\n * Example:\n *\n * ```\n * this.MANY_SEP({\n * SEP:Comma,\n * DEF: () => {\n * this.CONSUME(Number};\n * // ...\n * })\n * ```\n *\n * Note that because this DSL method always requires more than one argument the options object is always required\n * and it is not possible to use a shorter form like in the MANY DSL method.\n *\n * Note that for the purposes of deciding on whether or not another iteration exists\n * Only a single Token is examined (The separator). Therefore if the grammar being implemented is\n * so \"crazy\" to require multiple tokens to identify an item separator please use the more basic DSL methods\n * to implement it.\n *\n * As in CONSUME the index in the method name indicates the occurrence\n * of the repetition production in it's top rule.\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n */\n MANY_SEP: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP1: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP2: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP3: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP4: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP5: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP6: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP7: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP8: (options: ManySepMethodOpts<any>) => void;\n MANY_SEP9: (options: ManySepMethodOpts<any>) => void;\n /**\n * Convenience method, same as MANY but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause a parsing error.\n *\n * @see MANY\n *\n * @param actionORMethodDef - The grammar action to optionally invoke multiple times\n * or an \"OPTIONS\" object describing the grammar action and optional properties.\n *\n */\n AT_LEAST_ONE: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE1: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE2: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE3: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE4: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE5: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE6: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE7: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE8: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n AT_LEAST_ONE9: (\n actionORMethodDef: GrammarAction<any> | DSLMethodOptsWithErr<any>,\n ) => void;\n /**\n * Convenience method, same as MANY_SEP but the repetition is of one or more.\n * failing to match at least one repetition will result in a parsing error and\n * cause the parser to attempt error recovery.\n *\n * Note that an additional optional property ERR_MSG can be used to provide custom error messages.\n *\n * @see MANY_SEP\n *\n * @param options - An object defining the grammar of each iteration and the separator between iterations\n *\n * @return ISeparatedIterationResult<OUT>\n */\n AT_LEAST_ONE_SEP: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP1: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP2: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP3: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP4: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP5: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP6: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP7: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP8: (options: AtLeastOneSepMethodOpts<any>) => void;\n AT_LEAST_ONE_SEP9: (options: AtLeastOneSepMethodOpts<any>) => void;\n /**\n * Perform an action that is only executed during actual parsing and not during parser initialization.\n * (When a lot of this secretly return null)\n * @param impl\n * @constructor\n */\n ACTION: <T>(impl: () => T) => T;\n BACKTRACK: BacktrackFunc;\n SUBRULE: SubRuleFunc;\n SUBRULE1: SubRuleFunc;\n SUBRULE2: SubRuleFunc;\n SUBRULE3: SubRuleFunc;\n SUBRULE4: SubRuleFunc;\n SUBRULE5: SubRuleFunc;\n SUBRULE6: SubRuleFunc;\n SUBRULE7: SubRuleFunc;\n SUBRULE8: SubRuleFunc;\n SUBRULE9: SubRuleFunc;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@traqula/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.18",
|
|
5
5
|
"description": "Core components of Traqula",
|
|
6
6
|
"lsd:module": true,
|
|
7
7
|
"license": "MIT",
|
|
@@ -47,5 +47,5 @@
|
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@chevrotain/types": "^11.0.3"
|
|
49
49
|
},
|
|
50
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "1bb6a7d67631010ee01b325e33ff76f2f7530e02"
|
|
51
51
|
}
|