grammar-composer 0.2.3 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +2 -2
  2. package/dist/exports/Exports.d.ts +2 -0
  3. package/dist/exports/Exports.d.ts.map +1 -0
  4. package/dist/exports/Exports.js +2 -0
  5. package/dist/exports/Exports.js.map +1 -0
  6. package/dist/{GrammarComposer.d.ts → parser-generator/Grammar.d.ts} +2 -1
  7. package/dist/parser-generator/Grammar.d.ts.map +1 -0
  8. package/dist/{GrammarComposer.js → parser-generator/Grammar.js} +84 -27
  9. package/dist/parser-generator/Grammar.js.map +1 -0
  10. package/dist/{TopDownParser.d.ts → parser-generator/TopDownParser.d.ts} +3 -2
  11. package/dist/parser-generator/TopDownParser.d.ts.map +1 -0
  12. package/dist/{TopDownParser.js → parser-generator/TopDownParser.js} +13 -8
  13. package/dist/parser-generator/TopDownParser.js.map +1 -0
  14. package/dist/tests/Test.d.ts +2 -0
  15. package/dist/tests/Test.d.ts.map +1 -0
  16. package/dist/{Test.js → tests/Test.js} +6 -6
  17. package/dist/tests/Test.js.map +1 -0
  18. package/dist/{test-data → tests/test-data}/TestData.d.ts +1 -0
  19. package/dist/tests/test-data/TestData.d.ts.map +1 -0
  20. package/dist/tests/test-data/TestData.js.map +1 -0
  21. package/dist/{test-grammars → tests/test-grammars}/JsonGrammar.d.ts +2 -1
  22. package/dist/tests/test-grammars/JsonGrammar.d.ts.map +1 -0
  23. package/dist/{test-grammars → tests/test-grammars}/JsonGrammar.js +1 -1
  24. package/dist/tests/test-grammars/JsonGrammar.js.map +1 -0
  25. package/dist/{test-grammars → tests/test-grammars}/RegExpGrammar.d.ts +2 -1
  26. package/dist/tests/test-grammars/RegExpGrammar.d.ts.map +1 -0
  27. package/dist/{test-grammars → tests/test-grammars}/RegExpGrammar.js +1 -1
  28. package/dist/tests/test-grammars/RegExpGrammar.js.map +1 -0
  29. package/dist/{test-grammars → tests/test-grammars}/XmlGrammar.d.ts +2 -1
  30. package/dist/tests/test-grammars/XmlGrammar.d.ts.map +1 -0
  31. package/dist/{test-grammars → tests/test-grammars}/XmlGrammar.js +1 -1
  32. package/dist/tests/test-grammars/XmlGrammar.js.map +1 -0
  33. package/dist/utilities/Timer.d.ts +1 -0
  34. package/dist/utilities/Timer.d.ts.map +1 -0
  35. package/dist/utilities/Timer.js +1 -1
  36. package/dist/utilities/{utilities.d.ts → Utilities.d.ts} +1 -0
  37. package/dist/utilities/Utilities.d.ts.map +1 -0
  38. package/package.json +5 -5
  39. package/src/exports/Exports.ts +1 -0
  40. package/src/{GrammarComposer.ts → parser-generator/Grammar.ts} +94 -30
  41. package/src/{TopDownParser.ts → parser-generator/TopDownParser.ts} +15 -12
  42. package/src/{Test.ts → tests/Test.ts} +6 -6
  43. package/src/{test-grammars → tests/test-grammars}/JsonGrammar.ts +1 -1
  44. package/src/{test-grammars → tests/test-grammars}/RegExpGrammar.ts +1 -1
  45. package/src/{test-grammars → tests/test-grammars}/XmlGrammar.ts +1 -1
  46. package/src/utilities/Timer.ts +1 -1
  47. package/tsconfig.json +53 -103
  48. package/dist/Exports.d.ts +0 -1
  49. package/dist/Exports.js +0 -2
  50. package/dist/Exports.js.map +0 -1
  51. package/dist/Grammar.d.ts +0 -62
  52. package/dist/Grammar.js +0 -376
  53. package/dist/Grammar.js.map +0 -1
  54. package/dist/GrammarComposer.js.map +0 -1
  55. package/dist/Grammars/JsonGrammar.d.ts +0 -16
  56. package/dist/Grammars/JsonGrammar.js +0 -74
  57. package/dist/Grammars/JsonGrammar.js.map +0 -1
  58. package/dist/Grammars/XmlGrammar.d.ts +0 -13
  59. package/dist/Grammars/XmlGrammar.js +0 -74
  60. package/dist/Grammars/XmlGrammar.js.map +0 -1
  61. package/dist/ParserTest.d.ts +0 -1
  62. package/dist/ParserTest.js +0 -37
  63. package/dist/ParserTest.js.map +0 -1
  64. package/dist/Test.d.ts +0 -1
  65. package/dist/Test.js.map +0 -1
  66. package/dist/TestData.d.ts +0 -5
  67. package/dist/TestData.js +0 -466
  68. package/dist/TestData.js.map +0 -1
  69. package/dist/TopDownParser.js.map +0 -1
  70. package/dist/data/TestData.d.ts +0 -5
  71. package/dist/data/TestData.js +0 -466
  72. package/dist/data/TestData.js.map +0 -1
  73. package/dist/test-data/TestData.js.map +0 -1
  74. package/dist/test-grammars/JsonGrammar.js.map +0 -1
  75. package/dist/test-grammars/RegExpGrammar.js.map +0 -1
  76. package/dist/test-grammars/XmlGrammar.js.map +0 -1
  77. /package/dist/{test-data → tests/test-data}/TestData.js +0 -0
  78. /package/dist/utilities/{utilities.js → Utilities.js} +0 -0
  79. /package/dist/utilities/{utilities.js.map → Utilities.js.map} +0 -0
  80. /package/src/{test-data → tests/test-data}/TestData.ts +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "grammar-composer",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "Defines and generates parsers from composable grammar definitions. Includes advanced features like lexer-free parsing, selective packrat memoization and static analysis.",
5
5
  "author": "Rotem Dan",
6
6
  "license": "MIT",
@@ -19,7 +19,7 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/rotemdan/grammar-composer/issues"
21
21
  },
22
- "main": "./dist/GrammarComposer.js",
22
+ "main": "./dist/exports/Exports.js",
23
23
  "type": "module",
24
24
  "files": [
25
25
  "dist",
@@ -29,12 +29,12 @@
29
29
  "README.md"
30
30
  ],
31
31
  "scripts": {
32
- "test": "node dist/Test.js"
32
+ "test": "node dist/tests/Test.js"
33
33
  },
34
34
  "dependencies": {
35
- "regexp-composer": "^0.2.2"
35
+ "regexp-composer": "~0.4.0"
36
36
  },
37
37
  "devDependencies": {
38
- "@types/node": "^22.10.2"
38
+ "@types/node": "~26.2.0"
39
39
  }
40
40
  }
@@ -0,0 +1 @@
1
+ export * from '../parser-generator/Grammar.js'
@@ -1,5 +1,5 @@
1
1
  import { Pattern, buildRegExp, inputStart, isPatternOptional } from 'regexp-composer'
2
- import { isArray, isBoolean, isFunction, isString } from "./utilities/Utilities.js"
2
+ import { isArray, isBoolean, isFunction, isString } from '../utilities/Utilities.js'
3
3
 
4
4
  import { parse } from './TopDownParser.js'
5
5
 
@@ -24,7 +24,7 @@ export function buildGrammar<T extends { [key: string]: any }>(obj: T | (new ()
24
24
  continue
25
25
  }
26
26
 
27
- const productionContent = objectProperty()
27
+ const productionContent = objectProperty.call(obj)
28
28
  const normalizedProduction = productionToGrammarElement(productionContent)
29
29
 
30
30
  const newNonterminal = nonterminal(key, normalizedProduction)
@@ -69,7 +69,7 @@ export function buildGrammar<T extends { [key: string]: any }>(obj: T | (new ()
69
69
  nonterminals,
70
70
  startProductionName,
71
71
  uniqueIdCounter
72
- )
72
+ )
73
73
  }
74
74
 
75
75
  function prepareGrammarElement(
@@ -128,6 +128,18 @@ function prepareGrammarElement(
128
128
  throw new Error(`Couldn't resolve function reference in grammar element: ${JSON.stringify(element)}`)
129
129
  }
130
130
 
131
+ if (element.cached !== undefined || element.uniqueId !== undefined) {
132
+ const clonedNonterminal = { ...nonterminal }
133
+
134
+ if (element.cached !== undefined) {
135
+ clonedNonterminal.cached = element.cached
136
+ }
137
+
138
+ clonedNonterminal.uniqueId = getUniqueId()
139
+
140
+ return clonedNonterminal
141
+ }
142
+
131
143
  if (nonterminal.uniqueId === undefined) {
132
144
  nonterminal.uniqueId = getUniqueId()
133
145
  }
@@ -147,7 +159,7 @@ function detectAndAnnotateOptionalNodes(rootNode: GrammarElement) {
147
159
  const visitedNodes = new Set<GrammarElement>()
148
160
 
149
161
  const resolvedNodes = new Map<GrammarElement, boolean>()
150
- const unresolvedNodes = new Map<GrammarElement, Set<GrammarElement>>()
162
+ const unresolvedNodes = new Map<GrammarElement, { dependencies: Set<GrammarElement>, isChoice: boolean }>()
151
163
 
152
164
  function processDepthFirst(node: GrammarElement): boolean | undefined {
153
165
  if (visitedNodes.has(node)) {
@@ -177,24 +189,23 @@ function detectAndAnnotateOptionalNodes(rootNode: GrammarElement) {
177
189
 
178
190
  return result
179
191
  } else {
180
- unresolvedNodes.set(node, new Set([node.content]))
192
+ unresolvedNodes.set(node, { dependencies: new Set([node.content]), isChoice: false })
181
193
 
182
194
  return undefined
183
195
  }
184
196
  }
185
197
 
186
- case 'Sequence':
187
- case 'Choice': {
198
+ case 'Sequence': {
188
199
  const dependencies = new Set<GrammarElement>()
189
200
 
190
- let allResolvedElementsAreOptional = true
201
+ let hasNonOptionalResolvedMember = false
191
202
 
192
203
  for (const element of node.members) {
193
204
  const result = processDepthFirst(element)
194
205
 
195
206
  if (isBoolean(result)) {
196
- if (result == false) {
197
- allResolvedElementsAreOptional = false
207
+ if (result === false) {
208
+ hasNonOptionalResolvedMember = true
198
209
  }
199
210
  } else {
200
211
  dependencies.add(element)
@@ -205,12 +216,51 @@ function detectAndAnnotateOptionalNodes(rootNode: GrammarElement) {
205
216
  resolvedNodes.set(node, true)
206
217
 
207
218
  return true
208
- } else if (dependencies.size == 0 || !allResolvedElementsAreOptional) {
209
- resolvedNodes.set(node, allResolvedElementsAreOptional)
219
+ } else if (hasNonOptionalResolvedMember) {
220
+ resolvedNodes.set(node, false)
221
+
222
+ return false
223
+ } else if (dependencies.size == 0) {
224
+ resolvedNodes.set(node, true)
210
225
 
211
- return allResolvedElementsAreOptional
226
+ return true
212
227
  } else {
213
- unresolvedNodes.set(node, dependencies)
228
+ unresolvedNodes.set(node, { dependencies, isChoice: false })
229
+
230
+ return undefined
231
+ }
232
+ }
233
+
234
+ case 'Choice': {
235
+ const dependencies = new Set<GrammarElement>()
236
+ let hasOptionalResolvedMember = false
237
+
238
+ for (const element of node.members) {
239
+ const result = processDepthFirst(element)
240
+
241
+ if (isBoolean(result)) {
242
+ if (result === true) {
243
+ hasOptionalResolvedMember = true
244
+ }
245
+ } else {
246
+ dependencies.add(element)
247
+ }
248
+ }
249
+
250
+ if (node.optional == true) {
251
+ resolvedNodes.set(node, true)
252
+
253
+ return true
254
+ } else if (hasOptionalResolvedMember) {
255
+ resolvedNodes.set(node, true)
256
+
257
+ return true
258
+ } else if (dependencies.size == 0) {
259
+ resolvedNodes.set(node, false)
260
+
261
+ return false
262
+ } else {
263
+ unresolvedNodes.set(node, { dependencies, isChoice: true })
214
264
 
215
265
  return undefined
216
266
  }
@@ -231,13 +281,14 @@ function detectAndAnnotateOptionalNodes(rootNode: GrammarElement) {
231
281
  // If it stays false, it means that no improvement was made during the iteration,
232
282
  // and we should exit the loop.
233
283
  let atLastOneDependencyResolvedInAnyNode = false
284
+ const nodesToDelete: GrammarElement[] = []
234
285
 
235
286
  // Scan the unresolved nodes to locate any new resolved dependencies
236
- for (const [node, dependencies] of unresolvedNodes) {
237
- let nonOptionalDependencyFound = false
287
+ for (const [node, { dependencies, isChoice }] of unresolvedNodes) {
288
+ let nodeResolved = false
238
289
 
239
290
  // Iterate over all unresolved dependencies for the node
240
- for (const dependency of dependencies) {
291
+ for (const dependency of Array.from(dependencies)) {
241
292
  // Check if the dependency has been resolved
242
293
  const value = resolvedNodes.get(dependency)
243
294
 
@@ -245,28 +296,41 @@ function detectAndAnnotateOptionalNodes(rootNode: GrammarElement) {
245
296
  // If it did, record that some dependencies were resolved
246
297
  atLastOneDependencyResolvedInAnyNode = true
247
298
 
248
- if (value === false) {
249
- // If the value was false, then the entire target node must not be optional
250
- nonOptionalDependencyFound = true
251
-
252
- break
299
+ if (isChoice) {
300
+ if (value === true) {
301
+ resolvedNodes.set(node, true)
302
+ nodeResolved = true
303
+ break
304
+ }
253
305
  } else {
254
- // If the result was true, remove the dependency from the set
255
- dependencies.delete(dependency)
306
+ if (value === false) {
307
+ resolvedNodes.set(node, false)
308
+ nodeResolved = true
309
+ break
310
+ }
256
311
  }
312
+
313
+ dependencies.delete(dependency)
257
314
  }
258
315
  }
259
316
 
260
- // If either a non-optional dependency was found, or all dependencies were resolved,
261
- // resolve the target node:
262
- if (nonOptionalDependencyFound || dependencies.size === 0) {
263
- const isOptional = !nonOptionalDependencyFound
317
+ if (nodeResolved) {
318
+ nodesToDelete.push(node)
319
+ } else if (dependencies.size === 0) {
320
+ if (isChoice) {
321
+ resolvedNodes.set(node, false)
322
+ } else {
323
+ resolvedNodes.set(node, true)
324
+ }
264
325
 
265
- resolvedNodes.set(node, isOptional)
266
- unresolvedNodes.delete(node)
326
+ nodesToDelete.push(node)
267
327
  }
268
328
  }
269
329
 
330
+ for (const node of nodesToDelete) {
331
+ unresolvedNodes.delete(node)
332
+ }
333
+
270
334
  // If not even one dependency was eliminated for any node,
271
335
  // it means that only mutually cyclic nodes are left unresolved, so exit the loop.
272
336
  if (!atLastOneDependencyResolvedInAnyNode) {
@@ -1,4 +1,4 @@
1
- import { Grammar, GrammarElement, Terminal } from "./GrammarComposer.js"
1
+ import { Grammar, GrammarElement, Terminal } from './Grammar.js'
2
2
 
3
3
  export function parse(inputString: string, grammar: Grammar<any>) {
4
4
  const inputLength = inputString.length
@@ -78,12 +78,6 @@ export function parse(inputString: string, grammar: Grammar<any>) {
78
78
  }
79
79
 
80
80
  case 'PatternTerminal': {
81
- if (startOffset >= inputLength) {
82
- updateBestFailedMatchesIfNeeded(grammarElement, startOffset)
83
-
84
- return null
85
- }
86
-
87
81
  const substringToMatch = inputString.substring(startOffset)
88
82
 
89
83
  const matchResults = grammarElement.regExp.exec(substringToMatch)
@@ -209,6 +203,10 @@ export function parse(inputString: string, grammar: Grammar<any>) {
209
203
  break
210
204
  }
211
205
 
206
+ if (result.endOffset === readOffset) {
207
+ break
208
+ }
209
+
212
210
  if (result.nodes !== undefined) {
213
211
  nodes.push(...result.nodes)
214
212
  }
@@ -221,6 +219,11 @@ export function parse(inputString: string, grammar: Grammar<any>) {
221
219
  endOffset: readOffset,
222
220
  nodes: nodes.length > 0 ? nodes : undefined
223
221
  }
222
+ } else if (grammarElement.optional === true) {
223
+ return {
224
+ endOffset: startOffset,
225
+ nodes: undefined
226
+ }
224
227
  } else {
225
228
  return null
226
229
  }
@@ -252,10 +255,8 @@ export function parse(inputString: string, grammar: Grammar<any>) {
252
255
 
253
256
  const result = tryParse(grammar.rootElement, 0)
254
257
 
255
- const lastNode = result?.nodes?.[result.nodes.length - 1]
256
-
257
- if (lastNode && lastNode.endOffset >= inputLength) {
258
- return result.nodes
258
+ if (result && result.endOffset >= inputLength) {
259
+ return result.nodes ?? []
259
260
  } else {
260
261
  if (bestFailedMatches.length > 0) {
261
262
  const possibleMatches = bestFailedMatches.map(match => {
@@ -280,7 +281,9 @@ export function parse(inputString: string, grammar: Grammar<any>) {
280
281
 
281
282
  throw new Error(`Failed parsing the input text. Expected ${possibleMatchesString} at position ${bestFailedMatchesOffset}.`)
282
283
  } else {
283
- throw new Error(`Failed parsing the input text. Parsed length was ${lastNode?.endOffset ?? 0}. Input length was ${inputLength}.`)
284
+ const lastNode = result?.nodes?.[result.nodes.length - 1]
285
+
286
+ throw new Error(`Failed parsing the input text. Parsed length was ${lastNode?.endOffset ?? result?.endOffset ?? 0}. Input length was ${inputLength}.`)
284
287
  }
285
288
  }
286
289
  }
@@ -1,9 +1,9 @@
1
- import { Timer } from "./utilities/Timer.js"
2
- import { jsonSample1, jsonSample2 } from "./test-data/TestData.js"
3
- import { anyOf, buildGrammar } from "./GrammarComposer.js"
4
- import { JsonGrammar } from "./test-grammars/JsonGrammar.js"
5
- import { XmlGrammar } from "./test-grammars/XmlGrammar.js"
6
- import { RegExpGrammar } from "./test-grammars/RegExpGrammar.js"
1
+ import { Timer } from '../utilities/Timer.js'
2
+ import { jsonSample1, jsonSample2 } from './test-data/TestData.js'
3
+ import { anyOf, buildGrammar } from '../exports/Exports.js'
4
+ import { JsonGrammar } from './test-grammars/JsonGrammar.js'
5
+ import { XmlGrammar } from './test-grammars/XmlGrammar.js'
6
+ import { RegExpGrammar } from './test-grammars/RegExpGrammar.js'
7
7
 
8
8
  const log = console.log
9
9
 
@@ -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 JsonGrammar {
@@ -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 RegExpGrammar {
@@ -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 {};