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.
Files changed (81) hide show
  1. package/LICENSE.md +1 -1
  2. package/README.md +4 -3
  3. package/dist/exports/Exports.d.ts +2 -0
  4. package/dist/exports/Exports.d.ts.map +1 -0
  5. package/dist/exports/Exports.js +2 -0
  6. package/dist/exports/Exports.js.map +1 -0
  7. package/dist/{GrammarComposer.d.ts → parser-generator/Grammar.d.ts} +2 -1
  8. package/dist/parser-generator/Grammar.d.ts.map +1 -0
  9. package/dist/{GrammarComposer.js → parser-generator/Grammar.js} +84 -27
  10. package/dist/parser-generator/Grammar.js.map +1 -0
  11. package/dist/{TopDownParser.d.ts → parser-generator/TopDownParser.d.ts} +3 -2
  12. package/dist/parser-generator/TopDownParser.d.ts.map +1 -0
  13. package/dist/{TopDownParser.js → parser-generator/TopDownParser.js} +13 -8
  14. package/dist/parser-generator/TopDownParser.js.map +1 -0
  15. package/dist/tests/Test.d.ts +2 -0
  16. package/dist/tests/Test.d.ts.map +1 -0
  17. package/dist/{Test.js → tests/Test.js} +6 -6
  18. package/dist/tests/Test.js.map +1 -0
  19. package/dist/{test-data → tests/test-data}/TestData.d.ts +1 -0
  20. package/dist/tests/test-data/TestData.d.ts.map +1 -0
  21. package/dist/tests/test-data/TestData.js.map +1 -0
  22. package/dist/{test-grammars → tests/test-grammars}/JsonGrammar.d.ts +2 -1
  23. package/dist/tests/test-grammars/JsonGrammar.d.ts.map +1 -0
  24. package/dist/{test-grammars → tests/test-grammars}/JsonGrammar.js +1 -1
  25. package/dist/tests/test-grammars/JsonGrammar.js.map +1 -0
  26. package/dist/{test-grammars → tests/test-grammars}/RegExpGrammar.d.ts +4 -2
  27. package/dist/tests/test-grammars/RegExpGrammar.d.ts.map +1 -0
  28. package/dist/{test-grammars → tests/test-grammars}/RegExpGrammar.js +26 -19
  29. package/dist/tests/test-grammars/RegExpGrammar.js.map +1 -0
  30. package/dist/{test-grammars → tests/test-grammars}/XmlGrammar.d.ts +2 -1
  31. package/dist/tests/test-grammars/XmlGrammar.d.ts.map +1 -0
  32. package/dist/{test-grammars → tests/test-grammars}/XmlGrammar.js +1 -1
  33. package/dist/tests/test-grammars/XmlGrammar.js.map +1 -0
  34. package/dist/utilities/Timer.d.ts +1 -0
  35. package/dist/utilities/Timer.d.ts.map +1 -0
  36. package/dist/utilities/Timer.js +1 -1
  37. package/dist/utilities/{utilities.d.ts → Utilities.d.ts} +1 -0
  38. package/dist/utilities/Utilities.d.ts.map +1 -0
  39. package/package.json +5 -5
  40. package/src/exports/Exports.ts +1 -0
  41. package/src/{GrammarComposer.ts → parser-generator/Grammar.ts} +94 -30
  42. package/src/{TopDownParser.ts → parser-generator/TopDownParser.ts} +15 -12
  43. package/src/{Test.ts → tests/Test.ts} +6 -6
  44. package/src/{test-grammars → tests/test-grammars}/JsonGrammar.ts +1 -1
  45. package/src/{test-grammars → tests/test-grammars}/RegExpGrammar.ts +34 -20
  46. package/src/{test-grammars → tests/test-grammars}/XmlGrammar.ts +1 -1
  47. package/src/utilities/Timer.ts +1 -1
  48. package/tsconfig.json +53 -103
  49. package/dist/Exports.d.ts +0 -1
  50. package/dist/Exports.js +0 -2
  51. package/dist/Exports.js.map +0 -1
  52. package/dist/Grammar.d.ts +0 -62
  53. package/dist/Grammar.js +0 -376
  54. package/dist/Grammar.js.map +0 -1
  55. package/dist/GrammarComposer.js.map +0 -1
  56. package/dist/Grammars/JsonGrammar.d.ts +0 -16
  57. package/dist/Grammars/JsonGrammar.js +0 -74
  58. package/dist/Grammars/JsonGrammar.js.map +0 -1
  59. package/dist/Grammars/XmlGrammar.d.ts +0 -13
  60. package/dist/Grammars/XmlGrammar.js +0 -74
  61. package/dist/Grammars/XmlGrammar.js.map +0 -1
  62. package/dist/ParserTest.d.ts +0 -1
  63. package/dist/ParserTest.js +0 -37
  64. package/dist/ParserTest.js.map +0 -1
  65. package/dist/Test.d.ts +0 -1
  66. package/dist/Test.js.map +0 -1
  67. package/dist/TestData.d.ts +0 -5
  68. package/dist/TestData.js +0 -466
  69. package/dist/TestData.js.map +0 -1
  70. package/dist/TopDownParser.js.map +0 -1
  71. package/dist/data/TestData.d.ts +0 -5
  72. package/dist/data/TestData.js +0 -466
  73. package/dist/data/TestData.js.map +0 -1
  74. package/dist/test-data/TestData.js.map +0 -1
  75. package/dist/test-grammars/JsonGrammar.js.map +0 -1
  76. package/dist/test-grammars/RegExpGrammar.js.map +0 -1
  77. package/dist/test-grammars/XmlGrammar.js.map +0 -1
  78. /package/dist/{test-data → tests/test-data}/TestData.js +0 -0
  79. /package/dist/utilities/{utilities.js → Utilities.js} +0 -0
  80. /package/dist/utilities/{utilities.js.map → Utilities.js.map} +0 -0
  81. /package/src/{test-data → tests/test-data}/TestData.ts +0 -0
@@ -1,9 +1,9 @@
1
- import * as G from '../GrammarComposer.js'
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 level productions
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.oneOrMore(this.element)
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(letter))),
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', digit),
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
- codepoint = () => G.pattern([
177
- '\\u',
178
- '{',
179
- R.captureAs('value', R.oneOrMore(hexDigit)),
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(letterOrDigit)),
216
+ R.captureAs('property', R.oneOrMore(R.anyOf(letter, digit, '_', '-'))),
205
217
  R.possibly([
206
218
  '=',
207
- R.captureAs('value', R.oneOrMore(letterOrDigit)),
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.anyChar),
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: '\\d',
292
- nonWord: '\\D',
305
+ word: '\\w',
306
+ nonWord: '\\W',
293
307
  wordBoundary: '\\b',
294
308
  nonWordBoundary: '\\B',
295
309
  formFeed: '\\f',
@@ -1,4 +1,4 @@
1
- import * as G from "../GrammarComposer.js"
1
+ import * as G from '../../exports/Exports.js'
2
2
  import * as R from 'regexp-composer'
3
3
 
4
4
  export class XmlGrammar {
@@ -1,4 +1,4 @@
1
- import { roundToDigits } from "./Utilities.js"
1
+ import { roundToDigits } from './Utilities.js'
2
2
 
3
3
  declare const chrome: any
4
4
  declare const process: any
package/tsconfig.json CHANGED
@@ -1,105 +1,55 @@
1
1
  {
2
- "include": [
3
- "src/**/*"
4
- ],
5
- "compilerOptions": {
6
- /* Visit https://aka.ms/tsconfig to read more about this file */
7
- /* Projects */
8
- // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
9
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
10
- // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
11
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
12
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
13
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
14
- /* Language and Environment */
15
- "target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
16
- // "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
17
- // "jsx": "preserve", /* Specify what JSX code is generated. */
18
- // "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
19
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
20
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
21
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
22
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
23
- // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
24
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
25
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
26
- // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
27
- /* Modules */
28
- "module": "Node16", /* Specify what module code is generated. */
29
- // "rootDir": "./", /* Specify the root folder within your source files. */
30
- "moduleResolution": "Node16", /* Specify how TypeScript looks up a file from a given module specifier. */
31
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
32
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
33
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
34
- // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
35
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
36
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
37
- // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
38
- // "allowImportingTsExtensions": true, /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */
39
- // "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
40
- // "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
41
- // "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
42
- // "noUncheckedSideEffectImports": true, /* Check side effect imports. */
43
- // "resolveJsonModule": true, /* Enable importing .json files. */
44
- // "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
45
- // "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
46
- /* JavaScript Support */
47
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
48
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
49
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
50
- /* Emit */
51
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
52
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
53
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
54
- "sourceMap": true, /* Create source map files for emitted JavaScript files. */
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
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=Exports.js.map
@@ -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 {};