clarity-pattern-parser 11.4.0 → 11.4.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/dist/grammar_v2/patterns/Grammar.d.ts +23 -0
- package/dist/grammar_v2/patterns/patterns/grammar.d.ts +87 -0
- package/dist/grammar_v2/patterns/patterns/grammar.test.d.ts +1 -0
- package/dist/index.browser.js +8 -6
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +8 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +8 -6
- package/dist/index.js.map +1 -1
- package/dist/patterns/Cursor.d.ts +1 -1
- package/package.json +1 -1
- package/src/grammar_v2/patterns/Grammar.ts +170 -0
- package/src/grammar_v2/patterns/patterns/cpat.cpat +91 -0
- package/src/grammar_v2/patterns/patterns/grammar.test.ts +218 -0
- package/src/grammar_v2/patterns/patterns/grammar.ts +103 -0
- package/src/patterns/Cursor.ts +6 -6
- package/src/patterns/Regex.ts +4 -2
- package/src/patterns/Sequence.test.ts +11 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { GrammarFile } from "../../grammar/Grammar";
|
|
2
|
+
import { Pattern } from "../../patterns/Pattern";
|
|
3
|
+
export type Decorator = (pattern: Pattern, arg?: string | boolean | number | null | Record<string, any> | any[]) => void;
|
|
4
|
+
export interface GrammarOptions {
|
|
5
|
+
resolveImport?: (resource: string, originResource: string | null) => Promise<GrammarFile>;
|
|
6
|
+
resolveImportSync?: (resource: string, originResource: string | null) => GrammarFile;
|
|
7
|
+
originResource?: string | null;
|
|
8
|
+
params?: Pattern[];
|
|
9
|
+
decorators?: Record<string, Decorator>;
|
|
10
|
+
}
|
|
11
|
+
export declare class Grammar {
|
|
12
|
+
private _options;
|
|
13
|
+
private _parseContext;
|
|
14
|
+
private _resolveImportSync;
|
|
15
|
+
constructor(options: GrammarOptions);
|
|
16
|
+
private _resolveImportsSync;
|
|
17
|
+
private _processImportSync;
|
|
18
|
+
private _getWithParams;
|
|
19
|
+
private _processUseParams;
|
|
20
|
+
private _tryToParse;
|
|
21
|
+
private _flattenExpressions;
|
|
22
|
+
private _unwrapNode;
|
|
23
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { Expression } from "../../../patterns/Expression";
|
|
2
|
+
import { Literal } from "../../../patterns/Literal";
|
|
3
|
+
import { Optional } from "../../../patterns/Optional";
|
|
4
|
+
import { Options } from "../../../patterns/Options";
|
|
5
|
+
import { Regex } from "../../../patterns/Regex";
|
|
6
|
+
import { Repeat } from "../../../patterns/Repeat";
|
|
7
|
+
import { Sequence } from "../../../patterns/Sequence";
|
|
8
|
+
export declare const syntax: Literal;
|
|
9
|
+
export declare const imprt: Literal;
|
|
10
|
+
export declare const useParams: Literal;
|
|
11
|
+
export declare const withParams: Literal;
|
|
12
|
+
export declare const from: Literal;
|
|
13
|
+
export declare const right: Literal;
|
|
14
|
+
export declare const ws: Regex;
|
|
15
|
+
export declare const ls: Regex;
|
|
16
|
+
export declare const assign: Literal;
|
|
17
|
+
export declare const bar: Literal;
|
|
18
|
+
export declare const greedyBar: Literal;
|
|
19
|
+
export declare const concat: Literal;
|
|
20
|
+
export declare const colon: Literal;
|
|
21
|
+
export declare const openParen: Literal;
|
|
22
|
+
export declare const closeParen: Literal;
|
|
23
|
+
export declare const openSquareBracket: Literal;
|
|
24
|
+
export declare const closeSquareBracket: Literal;
|
|
25
|
+
export declare const openBracket: Literal;
|
|
26
|
+
export declare const closeBracket: Literal;
|
|
27
|
+
export declare const comma: Regex;
|
|
28
|
+
export declare const trim: Literal;
|
|
29
|
+
export declare const not: Literal;
|
|
30
|
+
export declare const optional: Literal;
|
|
31
|
+
export declare const newLine: Regex;
|
|
32
|
+
export declare const syntaxVersion: Regex;
|
|
33
|
+
export declare const at: Literal;
|
|
34
|
+
export declare const optionalWS: Optional;
|
|
35
|
+
export declare const optionalLS: Optional;
|
|
36
|
+
export declare const literal: Regex;
|
|
37
|
+
export declare const regex: Regex;
|
|
38
|
+
export declare const integer: Regex;
|
|
39
|
+
export declare const name: Regex;
|
|
40
|
+
export declare const patternName: Regex;
|
|
41
|
+
export declare const patternIdentifier: Regex;
|
|
42
|
+
export declare const resource: Regex;
|
|
43
|
+
export declare const comment: Regex;
|
|
44
|
+
export declare const jsonString: Regex;
|
|
45
|
+
export declare const jsonNumber: Regex;
|
|
46
|
+
export declare const trueLiteral: Literal;
|
|
47
|
+
export declare const falseLiteral: Literal;
|
|
48
|
+
export declare const jsonBoolean: Options;
|
|
49
|
+
export declare const jsonNull: Literal;
|
|
50
|
+
export declare const jsonArrayItems: Repeat;
|
|
51
|
+
export declare const jsonArray: Sequence;
|
|
52
|
+
export declare const jsonObjectPropertyName: Regex;
|
|
53
|
+
export declare const jsonObjectProperty: Sequence;
|
|
54
|
+
export declare const jsonObjectProperties: Repeat;
|
|
55
|
+
export declare const jsonObject: Sequence;
|
|
56
|
+
export declare const jsonValue: Options;
|
|
57
|
+
export declare const syntaxStatement: Sequence;
|
|
58
|
+
export declare const decorationName: Regex;
|
|
59
|
+
export declare const decorationStatement: Sequence;
|
|
60
|
+
export declare const useParamPatterns: Repeat;
|
|
61
|
+
export declare const useParamsStatement: Sequence;
|
|
62
|
+
export declare const withParamStatements: Repeat;
|
|
63
|
+
export declare const withParamsExpr: Sequence;
|
|
64
|
+
export declare const patternNames: Repeat;
|
|
65
|
+
export declare const importedPatterns: Sequence;
|
|
66
|
+
export declare const importStatement: Sequence;
|
|
67
|
+
export declare const notExpr: Sequence;
|
|
68
|
+
export declare const optionalExpr: Sequence;
|
|
69
|
+
export declare const rightAssociationExpr: Sequence;
|
|
70
|
+
export declare const unaryPatternExpr: Expression;
|
|
71
|
+
export declare const repeatBounds: Sequence;
|
|
72
|
+
export declare const oneOrMore: Literal;
|
|
73
|
+
export declare const zeroOrMore: Literal;
|
|
74
|
+
export declare const repeatOptions: Options;
|
|
75
|
+
export declare const delimiter: Sequence;
|
|
76
|
+
export declare const repeatExpr: Sequence;
|
|
77
|
+
export declare const sequenceExpr: Sequence;
|
|
78
|
+
export declare const optionsExpr: Sequence;
|
|
79
|
+
export declare const greedyOptionsExpr: Sequence;
|
|
80
|
+
export declare const patternGroupExpr: Sequence;
|
|
81
|
+
export declare const exportPattern: Regex;
|
|
82
|
+
export declare const patternExpr: Expression;
|
|
83
|
+
export declare const patternAssignment: Sequence;
|
|
84
|
+
export declare const statement: Options;
|
|
85
|
+
export declare const statements: Repeat;
|
|
86
|
+
export declare const cpat: Sequence;
|
|
87
|
+
export declare const grammar: Sequence;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.browser.js
CHANGED
|
@@ -435,7 +435,7 @@
|
|
|
435
435
|
|
|
436
436
|
class Cursor {
|
|
437
437
|
get text() {
|
|
438
|
-
return this.
|
|
438
|
+
return this._chars.join("");
|
|
439
439
|
}
|
|
440
440
|
get isOnFirst() {
|
|
441
441
|
return this._index === 0;
|
|
@@ -483,12 +483,12 @@
|
|
|
483
483
|
return this._history.error != null;
|
|
484
484
|
}
|
|
485
485
|
get currentChar() {
|
|
486
|
-
return this.
|
|
486
|
+
return this._chars[this._index];
|
|
487
487
|
}
|
|
488
488
|
constructor(text) {
|
|
489
|
-
this.
|
|
489
|
+
this._chars = [...text];
|
|
490
490
|
this._index = 0;
|
|
491
|
-
this._length =
|
|
491
|
+
this._length = this._chars.length;
|
|
492
492
|
this._history = new CursorHistory();
|
|
493
493
|
}
|
|
494
494
|
hasNext() {
|
|
@@ -522,7 +522,7 @@
|
|
|
522
522
|
return this._length - 1;
|
|
523
523
|
}
|
|
524
524
|
getChars(first, last) {
|
|
525
|
-
return this.
|
|
525
|
+
return this._chars.slice(first, last + 1).join("");
|
|
526
526
|
}
|
|
527
527
|
recordMatch(pattern, node) {
|
|
528
528
|
this._history.recordMatch(pattern, node);
|
|
@@ -771,7 +771,9 @@
|
|
|
771
771
|
}
|
|
772
772
|
processResult(cursor, result) {
|
|
773
773
|
const currentIndex = cursor.index;
|
|
774
|
-
const
|
|
774
|
+
const match = result[0];
|
|
775
|
+
const matchLength = [...match].length;
|
|
776
|
+
const newIndex = currentIndex + matchLength - 1;
|
|
775
777
|
this._node = new Node("regex", this._name, currentIndex, newIndex, undefined, result[0]);
|
|
776
778
|
cursor.moveTo(newIndex);
|
|
777
779
|
cursor.recordMatch(this, this._node);
|