clarity-pattern-parser 8.2.0 → 8.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.
- package/.vscode/settings.json +5 -1
- package/README.md +2 -2
- package/dist/grammar/Grammar.d.ts +22 -3
- package/dist/grammar/patterns/import.d.ts +2 -0
- package/dist/index.browser.js +325 -193
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +323 -191
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +323 -191
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ast/Node.ts +1 -1
- package/src/grammar/Grammar.test.ts +67 -21
- package/src/grammar/Grammar.ts +120 -13
- package/src/grammar/patterns/grammar.ts +9 -6
- package/src/grammar/patterns/import.ts +29 -0
- package/src/grammar/spec.md +26 -2
- package/src/patterns/And.ts +1 -5
- package/src/patterns/FiniteRepeat.ts +2 -1
- package/src/patterns/InfiniteRepeat.test.ts +9 -23
- package/src/patterns/InfiniteRepeat.ts +7 -2
- package/src/patterns/Or.ts +2 -1
package/.vscode/settings.json
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
"typescript.tsdk": "node_modules/typescript/lib"
|
|
2
|
+
"typescript.tsdk": "node_modules/typescript/lib",
|
|
3
|
+
"typescript.preferences.importModuleSpecifierEnding": "minimal",
|
|
4
|
+
"javascript.preferences.importModuleSpecifierEnding": "minimal",
|
|
5
|
+
"typescript.preferences.importModuleSpecifier": "relative",
|
|
6
|
+
"javascript.preferences.importModuleSpecifier": "relative"
|
|
3
7
|
}
|
package/README.md
CHANGED
|
@@ -129,14 +129,14 @@ ast.toJson(2); // Look Below for output
|
|
|
129
129
|
```
|
|
130
130
|
|
|
131
131
|
## Or
|
|
132
|
-
The `Or` pattern
|
|
132
|
+
The `Or` pattern matches any of the patterns given to the constructor.
|
|
133
133
|
```ts
|
|
134
134
|
import { Or, Literal } from "clarity-pattern-parser";
|
|
135
135
|
|
|
136
136
|
const jane = new Literal("jane", "Jane");
|
|
137
137
|
const john = new Literal("john", "John");
|
|
138
138
|
const firstName = new Or("first-name", [jane, john]);
|
|
139
|
-
const { ast }= firstName.exec("Jane");
|
|
139
|
+
const { ast } = firstName.exec("Jane");
|
|
140
140
|
|
|
141
141
|
ast.toJson(2)
|
|
142
142
|
```
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import { Pattern } from "../patterns/Pattern";
|
|
2
|
+
export interface GrammarMeta {
|
|
3
|
+
originPath?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface GrammarFile {
|
|
6
|
+
path: string;
|
|
7
|
+
expression: string;
|
|
8
|
+
}
|
|
9
|
+
export interface GrammarOptions {
|
|
10
|
+
resolveImport?: (path: string, originPath: string | null) => Promise<GrammarFile>;
|
|
11
|
+
meta?: GrammarMeta | null;
|
|
12
|
+
}
|
|
2
13
|
export declare class Grammar {
|
|
14
|
+
private _meta;
|
|
15
|
+
private _resolveImport;
|
|
3
16
|
private _parseContext;
|
|
4
17
|
private _autoComplete;
|
|
5
|
-
constructor();
|
|
6
|
-
|
|
18
|
+
constructor(options?: GrammarOptions);
|
|
19
|
+
import(path: string): Promise<Map<string, Pattern>>;
|
|
20
|
+
parse(expression: string): Promise<Map<string, Pattern>>;
|
|
21
|
+
parseString(expression: string): Map<string, Pattern>;
|
|
7
22
|
private _tryToParse;
|
|
23
|
+
private _hasImports;
|
|
8
24
|
private _cleanAst;
|
|
9
25
|
private _buildPatterns;
|
|
26
|
+
private _resolveImports;
|
|
10
27
|
private _buildLiteral;
|
|
11
28
|
private _buildRegex;
|
|
12
29
|
private _buildOr;
|
|
@@ -14,5 +31,7 @@ export declare class Grammar {
|
|
|
14
31
|
private _buildAnd;
|
|
15
32
|
private _buildRepeat;
|
|
16
33
|
private _buildAlias;
|
|
17
|
-
static parse(expression: string): Map<string, Pattern
|
|
34
|
+
static parse(expression: string, options?: GrammarOptions): Promise<Map<string, Pattern>>;
|
|
35
|
+
static import(path: string, options?: GrammarOptions): Promise<Map<string, Pattern>>;
|
|
36
|
+
static parseString(expression: string): Map<string, Pattern>;
|
|
18
37
|
}
|