grammar-composer 0.2.4 → 0.3.1
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.md +1 -1
- package/README.md +4 -3
- package/dist/exports/Exports.d.ts +2 -0
- package/dist/exports/Exports.d.ts.map +1 -0
- package/dist/exports/Exports.js +2 -0
- package/dist/exports/Exports.js.map +1 -0
- package/dist/{GrammarComposer.d.ts → parser-generator/Grammar.d.ts} +2 -1
- package/dist/parser-generator/Grammar.d.ts.map +1 -0
- package/dist/{GrammarComposer.js → parser-generator/Grammar.js} +84 -27
- package/dist/parser-generator/Grammar.js.map +1 -0
- package/dist/{TopDownParser.d.ts → parser-generator/TopDownParser.d.ts} +3 -2
- package/dist/parser-generator/TopDownParser.d.ts.map +1 -0
- package/dist/{TopDownParser.js → parser-generator/TopDownParser.js} +13 -8
- package/dist/parser-generator/TopDownParser.js.map +1 -0
- package/dist/tests/Test.d.ts +2 -0
- package/dist/tests/Test.d.ts.map +1 -0
- package/dist/{Test.js → tests/Test.js} +6 -6
- package/dist/tests/Test.js.map +1 -0
- package/dist/{test-data → tests/test-data}/TestData.d.ts +1 -0
- package/dist/tests/test-data/TestData.d.ts.map +1 -0
- package/dist/tests/test-data/TestData.js.map +1 -0
- package/dist/{test-grammars → tests/test-grammars}/JsonGrammar.d.ts +2 -1
- package/dist/tests/test-grammars/JsonGrammar.d.ts.map +1 -0
- package/dist/{test-grammars → tests/test-grammars}/JsonGrammar.js +1 -1
- package/dist/tests/test-grammars/JsonGrammar.js.map +1 -0
- package/dist/{test-grammars → tests/test-grammars}/RegExpGrammar.d.ts +4 -2
- package/dist/tests/test-grammars/RegExpGrammar.d.ts.map +1 -0
- package/dist/{test-grammars → tests/test-grammars}/RegExpGrammar.js +26 -19
- package/dist/tests/test-grammars/RegExpGrammar.js.map +1 -0
- package/dist/{test-grammars → tests/test-grammars}/XmlGrammar.d.ts +2 -1
- package/dist/tests/test-grammars/XmlGrammar.d.ts.map +1 -0
- package/dist/{test-grammars → tests/test-grammars}/XmlGrammar.js +1 -1
- package/dist/tests/test-grammars/XmlGrammar.js.map +1 -0
- package/dist/utilities/Timer.d.ts +1 -0
- package/dist/utilities/Timer.d.ts.map +1 -0
- package/dist/utilities/Timer.js +1 -1
- package/dist/utilities/{utilities.d.ts → Utilities.d.ts} +1 -0
- package/dist/utilities/Utilities.d.ts.map +1 -0
- package/package.json +5 -5
- package/src/exports/Exports.ts +1 -0
- package/src/{GrammarComposer.ts → parser-generator/Grammar.ts} +94 -30
- package/src/{TopDownParser.ts → parser-generator/TopDownParser.ts} +15 -12
- package/src/{Test.ts → tests/Test.ts} +6 -6
- package/src/{test-grammars → tests/test-grammars}/JsonGrammar.ts +1 -1
- package/src/{test-grammars → tests/test-grammars}/RegExpGrammar.ts +34 -20
- package/src/{test-grammars → tests/test-grammars}/XmlGrammar.ts +1 -1
- package/src/utilities/Timer.ts +1 -1
- package/tsconfig.json +53 -103
- package/dist/Exports.d.ts +0 -1
- package/dist/Exports.js +0 -2
- package/dist/Exports.js.map +0 -1
- package/dist/Grammar.d.ts +0 -62
- package/dist/Grammar.js +0 -376
- package/dist/Grammar.js.map +0 -1
- package/dist/GrammarComposer.js.map +0 -1
- package/dist/Grammars/JsonGrammar.d.ts +0 -16
- package/dist/Grammars/JsonGrammar.js +0 -74
- package/dist/Grammars/JsonGrammar.js.map +0 -1
- package/dist/Grammars/XmlGrammar.d.ts +0 -13
- package/dist/Grammars/XmlGrammar.js +0 -74
- package/dist/Grammars/XmlGrammar.js.map +0 -1
- package/dist/ParserTest.d.ts +0 -1
- package/dist/ParserTest.js +0 -37
- package/dist/ParserTest.js.map +0 -1
- package/dist/Test.d.ts +0 -1
- package/dist/Test.js.map +0 -1
- package/dist/TestData.d.ts +0 -5
- package/dist/TestData.js +0 -466
- package/dist/TestData.js.map +0 -1
- package/dist/TopDownParser.js.map +0 -1
- package/dist/data/TestData.d.ts +0 -5
- package/dist/data/TestData.js +0 -466
- package/dist/data/TestData.js.map +0 -1
- package/dist/test-data/TestData.js.map +0 -1
- package/dist/test-grammars/JsonGrammar.js.map +0 -1
- package/dist/test-grammars/RegExpGrammar.js.map +0 -1
- package/dist/test-grammars/XmlGrammar.js.map +0 -1
- /package/dist/{test-data → tests/test-data}/TestData.js +0 -0
- /package/dist/utilities/{utilities.js → Utilities.js} +0 -0
- /package/dist/utilities/{utilities.js.map → Utilities.js.map} +0 -0
- /package/src/{test-data → tests/test-data}/TestData.ts +0 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import * as G from '
|
|
1
|
+
import * as G from '../../exports/Exports.js'
|
|
2
2
|
import * as R from 'regexp-composer'
|
|
3
3
|
|
|
4
4
|
export class RegExpGrammar {
|
|
5
5
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
6
|
-
// High
|
|
6
|
+
// High-level productions
|
|
7
7
|
//////////////////////////////////////////////////////////////////////////////////////////////
|
|
8
8
|
disjunction = () => [
|
|
9
9
|
this.sequence,
|
|
@@ -14,7 +14,7 @@ export class RegExpGrammar {
|
|
|
14
14
|
])
|
|
15
15
|
]
|
|
16
16
|
|
|
17
|
-
sequence = () => G.
|
|
17
|
+
sequence = () => G.zeroOrMore(this.element)
|
|
18
18
|
|
|
19
19
|
element = () => G.anyOf(
|
|
20
20
|
this.anchor,
|
|
@@ -66,14 +66,14 @@ export class RegExpGrammar {
|
|
|
66
66
|
)
|
|
67
67
|
|
|
68
68
|
uncapturedGroup = () => [
|
|
69
|
-
'(
|
|
69
|
+
'(?:',
|
|
70
70
|
this.disjunction,
|
|
71
71
|
')',
|
|
72
72
|
]
|
|
73
73
|
|
|
74
74
|
namedCaptureGroup = () => [
|
|
75
75
|
'(?<',
|
|
76
|
-
G.pattern(R.captureAs('name', R.oneOrMore(
|
|
76
|
+
G.pattern(R.captureAs('name', R.oneOrMore(identifierChar))),
|
|
77
77
|
'>',
|
|
78
78
|
this.disjunction,
|
|
79
79
|
')',
|
|
@@ -97,7 +97,7 @@ export class RegExpGrammar {
|
|
|
97
97
|
namedBackreference = () =>
|
|
98
98
|
G.pattern([
|
|
99
99
|
'\\k<',
|
|
100
|
-
R.captureAs('name',
|
|
100
|
+
R.captureAs('name', R.oneOrMore(identifierChar)),
|
|
101
101
|
'>',
|
|
102
102
|
])
|
|
103
103
|
|
|
@@ -148,6 +148,7 @@ export class RegExpGrammar {
|
|
|
148
148
|
this.charClass,
|
|
149
149
|
this.unicodeProperty,
|
|
150
150
|
this.notUnicodeProperty,
|
|
151
|
+
this.escapedCharacterClass,
|
|
151
152
|
this.charcodeOrEscapedChar,
|
|
152
153
|
this.unreservedCharLiteral
|
|
153
154
|
)
|
|
@@ -170,15 +171,26 @@ export class RegExpGrammar {
|
|
|
170
171
|
|
|
171
172
|
controlCharcode = () => G.pattern([
|
|
172
173
|
'\\c',
|
|
173
|
-
R.charRange('A', 'Z'),
|
|
174
|
+
R.anyOf(R.charRange('A', 'Z'), R.charRange('a', 'z')),
|
|
174
175
|
])
|
|
175
176
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
177
|
+
nullCharcode = () => G.pattern('\\0')
|
|
178
|
+
|
|
179
|
+
codepoint = () => G.anyOf(
|
|
180
|
+
G.pattern([
|
|
181
|
+
'\\u',
|
|
182
|
+
'{',
|
|
183
|
+
R.captureAs('value', R.repeated([1, 6], hexDigit)),
|
|
184
|
+
'}',
|
|
185
|
+
]),
|
|
186
|
+
G.pattern([
|
|
187
|
+
'\\u',
|
|
188
|
+
hexDigit,
|
|
189
|
+
hexDigit,
|
|
190
|
+
hexDigit,
|
|
191
|
+
hexDigit
|
|
192
|
+
])
|
|
193
|
+
)
|
|
182
194
|
|
|
183
195
|
codepointRange = () => G.pattern([
|
|
184
196
|
'\\u',
|
|
@@ -201,10 +213,10 @@ export class RegExpGrammar {
|
|
|
201
213
|
|
|
202
214
|
unicodePropertyBodyPattern: R.Pattern = [
|
|
203
215
|
'{',
|
|
204
|
-
R.captureAs('property', R.oneOrMore(
|
|
216
|
+
R.captureAs('property', R.oneOrMore(R.anyOf(letter, digit, '_', '-'))),
|
|
205
217
|
R.possibly([
|
|
206
218
|
'=',
|
|
207
|
-
R.captureAs('value', R.oneOrMore(
|
|
219
|
+
R.captureAs('value', R.oneOrMore(R.anyOf(letter, digit, '_', '-'))),
|
|
208
220
|
]),
|
|
209
221
|
'}',
|
|
210
222
|
]
|
|
@@ -217,9 +229,9 @@ export class RegExpGrammar {
|
|
|
217
229
|
G.oneOrMore(G.anyOf(
|
|
218
230
|
this.charRange,
|
|
219
231
|
this.codepointRange,
|
|
220
|
-
this.charClass,
|
|
221
232
|
this.unicodeProperty,
|
|
222
233
|
this.notUnicodeProperty,
|
|
234
|
+
this.escapedCharacterClass,
|
|
223
235
|
this.charcodeOrEscapedChar,
|
|
224
236
|
this.charClassChar
|
|
225
237
|
)),
|
|
@@ -235,7 +247,7 @@ export class RegExpGrammar {
|
|
|
235
247
|
|
|
236
248
|
charRangeElement = G.anyOf(
|
|
237
249
|
this.charcodeOrEscapedChar,
|
|
238
|
-
G.pattern(R.
|
|
250
|
+
G.pattern(R.notAnyOfChars(']')),
|
|
239
251
|
)
|
|
240
252
|
|
|
241
253
|
charRange = () => [
|
|
@@ -267,6 +279,8 @@ export class RegExpGrammar {
|
|
|
267
279
|
R.captureAs('nonWhitespace', escapedCharString.nonWhitespace),
|
|
268
280
|
R.captureAs('digit', escapedCharString.digit),
|
|
269
281
|
R.captureAs('nonDigit', escapedCharString.nonDigit),
|
|
282
|
+
R.captureAs('word', escapedCharString.word),
|
|
283
|
+
R.captureAs('nonWord', escapedCharString.nonWord),
|
|
270
284
|
R.captureAs('wordBoundary', escapedCharString.wordBoundary),
|
|
271
285
|
R.captureAs('nonWordBoundary', escapedCharString.nonWordBoundary),
|
|
272
286
|
R.captureAs('formFeed', escapedCharString.formFeed),
|
|
@@ -280,16 +294,16 @@ export class RegExpGrammar {
|
|
|
280
294
|
|
|
281
295
|
const digit = R.charRange('0', '9')
|
|
282
296
|
const letter = R.anyOf(R.charRange('a', 'z'), R.charRange('A', 'Z'))
|
|
283
|
-
const letterOrDigit = R.anyOf(letter, digit)
|
|
284
297
|
const hexDigit = R.anyOf(digit, R.charRange('a', 'f'), R.charRange('A', 'F'))
|
|
298
|
+
const identifierChar = R.anyOf(letter, digit, '_', '$')
|
|
285
299
|
|
|
286
300
|
const escapedCharString = {
|
|
287
301
|
whitespace: '\\s',
|
|
288
302
|
nonWhitespace: '\\S',
|
|
289
303
|
digit: '\\d',
|
|
290
304
|
nonDigit: '\\D',
|
|
291
|
-
word: '\\
|
|
292
|
-
nonWord: '\\
|
|
305
|
+
word: '\\w',
|
|
306
|
+
nonWord: '\\W',
|
|
293
307
|
wordBoundary: '\\b',
|
|
294
308
|
nonWordBoundary: '\\B',
|
|
295
309
|
formFeed: '\\f',
|
package/src/utilities/Timer.ts
CHANGED
package/tsconfig.json
CHANGED
|
@@ -1,105 +1,55 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
|
56
|
-
// "noEmit": true, /* Disable emitting files from a compilation. */
|
|
57
|
-
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
|
58
|
-
"outDir": "./dist", /* Specify an output folder for all emitted files. */
|
|
59
|
-
// "removeComments": true, /* Disable emitting comments. */
|
|
60
|
-
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
|
61
|
-
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
|
62
|
-
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
|
63
|
-
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
|
64
|
-
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
|
65
|
-
"emitBOM": false, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
|
66
|
-
"newLine": "lf", /* Set the newline character for emitting files. */
|
|
67
|
-
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
|
68
|
-
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
|
69
|
-
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
|
70
|
-
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
|
71
|
-
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
|
72
|
-
/* Interop Constraints */
|
|
73
|
-
"isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
|
|
74
|
-
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
|
75
|
-
// "isolatedDeclarations": true, /* Require sufficient annotation on exports so other tools can trivially generate declaration files. */
|
|
76
|
-
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
|
77
|
-
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
|
78
|
-
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
|
79
|
-
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
|
80
|
-
/* Type Checking */
|
|
81
|
-
"strict": true, /* Enable all strict type-checking options. */
|
|
82
|
-
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
|
83
|
-
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
|
84
|
-
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
|
85
|
-
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
|
86
|
-
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
|
87
|
-
// "strictBuiltinIteratorReturn": true, /* Built-in iterators are instantiated with a 'TReturn' type of 'undefined' instead of 'any'. */
|
|
88
|
-
"noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
|
89
|
-
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
|
90
|
-
"alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
|
91
|
-
// "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */
|
|
92
|
-
// "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */
|
|
93
|
-
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
|
94
|
-
"noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
|
95
|
-
// "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
|
|
96
|
-
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
|
97
|
-
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
|
98
|
-
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
|
99
|
-
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
|
100
|
-
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
|
101
|
-
/* Completeness */
|
|
102
|
-
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
|
103
|
-
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
|
104
|
-
}
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "nodenext",
|
|
11
|
+
"target": "esnext",
|
|
12
|
+
"types": ["node"],
|
|
13
|
+
// For nodejs:
|
|
14
|
+
// "lib": ["esnext"],
|
|
15
|
+
// "types": ["node"],
|
|
16
|
+
// and npm install -D @types/node
|
|
17
|
+
|
|
18
|
+
// Other Outputs
|
|
19
|
+
"sourceMap": true,
|
|
20
|
+
"declaration": true,
|
|
21
|
+
"declarationMap": true,
|
|
22
|
+
|
|
23
|
+
// Stricter Typechecking Options
|
|
24
|
+
// "noUncheckedIndexedAccess": true,
|
|
25
|
+
// "exactOptionalPropertyTypes": true,
|
|
26
|
+
|
|
27
|
+
// Style Options
|
|
28
|
+
"noImplicitReturns": true,
|
|
29
|
+
// "noImplicitOverride": true,
|
|
30
|
+
// "noUnusedLocals": true,
|
|
31
|
+
// "noUnusedParameters": true,
|
|
32
|
+
// "noFallthroughCasesInSwitch": true,
|
|
33
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
34
|
+
|
|
35
|
+
// Recommended Options
|
|
36
|
+
"strict": true,
|
|
37
|
+
"jsx": "react-jsx",
|
|
38
|
+
// "verbatimModuleSyntax": true,
|
|
39
|
+
"isolatedModules": true,
|
|
40
|
+
"noUncheckedSideEffectImports": true,
|
|
41
|
+
"moduleDetection": "force",
|
|
42
|
+
"skipLibCheck": true,
|
|
43
|
+
|
|
44
|
+
// Extended options not in generated tsconfig.json
|
|
45
|
+
"newLine": "lf",
|
|
46
|
+
"forceConsistentCasingInFileNames": true,
|
|
47
|
+
"alwaysStrict": true,
|
|
48
|
+
|
|
49
|
+
"noImplicitThis": true,
|
|
50
|
+
"strictBindCallApply": true,
|
|
51
|
+
"strictFunctionTypes": true,
|
|
52
|
+
|
|
53
|
+
"noErrorTruncation": true,
|
|
54
|
+
}
|
|
105
55
|
}
|
package/dist/Exports.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/Exports.js
DELETED
package/dist/Exports.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Exports.js","sourceRoot":"","sources":["../src/Exports.ts"],"names":[],"mappings":""}
|
package/dist/Grammar.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { Pattern } from 'regexp-composer';
|
|
2
|
-
export declare function buildGrammar<T extends {
|
|
3
|
-
[key: string]: any;
|
|
4
|
-
}>(obj: T | (new () => T), startProductionName: keyof T): Grammar<T>;
|
|
5
|
-
export declare function detectAndErrorOnLeftRecursion(rootNode: GrammarElement): void;
|
|
6
|
-
export declare function oneOrMore(content: Production): Repetition;
|
|
7
|
-
export declare function zeroOrMore(content: Production): Repetition;
|
|
8
|
-
export declare function anyOf(...members: Production[]): Choice;
|
|
9
|
-
export declare function bestOf(...members: Production[]): Choice;
|
|
10
|
-
export declare function possibly<T extends Production>(content: Production): T;
|
|
11
|
-
export declare function cached<T extends Production>(content: Production): T;
|
|
12
|
-
export declare function uncached<T extends Production>(content: Production): T;
|
|
13
|
-
export declare function pattern(pattern: Pattern): PatternTerminal;
|
|
14
|
-
export interface Grammar<T> {
|
|
15
|
-
rootElement: Nonterminal;
|
|
16
|
-
productions: {
|
|
17
|
-
[key in keyof T]: any;
|
|
18
|
-
};
|
|
19
|
-
maxElementId: number;
|
|
20
|
-
}
|
|
21
|
-
export type Production = string | GrammarElement | (() => Production) | Production[];
|
|
22
|
-
export type GrammarElement = StringTerminal | PatternTerminal | Nonterminal | Sequence | Repetition | Choice | NonterminalReference;
|
|
23
|
-
interface GrammarElementBase {
|
|
24
|
-
type: string;
|
|
25
|
-
optional: boolean;
|
|
26
|
-
uniqueId?: number;
|
|
27
|
-
cached?: boolean;
|
|
28
|
-
}
|
|
29
|
-
export type Terminal = StringTerminal | PatternTerminal;
|
|
30
|
-
export interface StringTerminal extends GrammarElementBase {
|
|
31
|
-
type: 'StringTerminal';
|
|
32
|
-
content: string;
|
|
33
|
-
}
|
|
34
|
-
export interface PatternTerminal extends GrammarElementBase {
|
|
35
|
-
type: 'PatternTerminal';
|
|
36
|
-
name: string;
|
|
37
|
-
pattern: Pattern | Pattern[];
|
|
38
|
-
regExp: RegExp;
|
|
39
|
-
}
|
|
40
|
-
export interface Nonterminal extends GrammarElementBase {
|
|
41
|
-
type: 'Nonterminal';
|
|
42
|
-
name: string;
|
|
43
|
-
content: GrammarElement;
|
|
44
|
-
}
|
|
45
|
-
export interface Sequence extends GrammarElementBase {
|
|
46
|
-
type: 'Sequence';
|
|
47
|
-
members: GrammarElement[];
|
|
48
|
-
}
|
|
49
|
-
export interface Repetition extends GrammarElementBase {
|
|
50
|
-
type: 'Repetition';
|
|
51
|
-
content: GrammarElement;
|
|
52
|
-
}
|
|
53
|
-
export interface Choice extends GrammarElementBase {
|
|
54
|
-
type: 'Choice';
|
|
55
|
-
members: GrammarElement[];
|
|
56
|
-
exhaustive: boolean;
|
|
57
|
-
}
|
|
58
|
-
export interface NonterminalReference extends GrammarElementBase {
|
|
59
|
-
type: 'NonterminalReference';
|
|
60
|
-
reference: Function;
|
|
61
|
-
}
|
|
62
|
-
export {};
|