clarity-pattern-parser 11.5.3 → 11.6.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/architecture.md +300 -0
- package/dist/grammar/Grammar.d.ts +24 -25
- package/dist/grammar/patterns/grammar.d.ts +99 -0
- package/dist/grammar/patterns/grammar.test.d.ts +1 -0
- package/dist/index.browser.js +2270 -2536
- package/dist/index.browser.js.map +1 -1
- package/dist/index.esm.js +2270 -2536
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +2270 -2536
- package/dist/index.js.map +1 -1
- package/dist/patterns/Expression.d.ts +3 -2
- package/grammar-guide.md +836 -0
- package/package.json +1 -1
- package/src/grammar/Grammar.test.ts +418 -0
- package/src/grammar/Grammar.ts +483 -515
- package/src/grammar/patterns/grammar.test.ts +276 -0
- package/src/grammar/patterns/grammar.ts +113 -37
- package/src/grammar/patterns.ts +6 -6
- package/src/patterns/Expression.ts +28 -13
- package/src/grammar/patterns/anonymousPattern.ts +0 -23
- package/src/grammar/patterns/body.ts +0 -22
- package/src/grammar/patterns/comment.ts +0 -4
- package/src/grammar/patterns/decoratorStatement.ts +0 -85
- package/src/grammar/patterns/import.ts +0 -88
- package/src/grammar/patterns/literal.ts +0 -4
- package/src/grammar/patterns/literals.ts +0 -21
- package/src/grammar/patterns/name.ts +0 -3
- package/src/grammar/patterns/optionsLiteral.ts +0 -25
- package/src/grammar/patterns/pattern.ts +0 -29
- package/src/grammar/patterns/regexLiteral.ts +0 -5
- package/src/grammar/patterns/repeatLiteral.ts +0 -71
- package/src/grammar/patterns/sequenceLiteral.ts +0 -24
- package/src/grammar/patterns/spaces.ts +0 -16
- package/src/grammar/patterns/statement.ts +0 -22
- package/src/grammar/patterns/takeUtilLiteral.ts +0 -20
- package/src/grammar/spec.md +0 -331
- package/src/grammar_v2/patterns/Grammar.ts +0 -170
- package/src/grammar_v2/patterns/patterns/cpat.cpat +0 -91
- package/src/grammar_v2/patterns/patterns/grammar.test.ts +0 -218
- package/src/grammar_v2/patterns/patterns/grammar.ts +0 -103
package/architecture.md
ADDED
|
@@ -0,0 +1,300 @@
|
|
|
1
|
+
# Clarity Pattern Parser - Architecture
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
Clarity Pattern Parser is a composable parsing library for TypeScript/JavaScript. It builds parsers from pattern primitives (literals, regex, sequences, options, repeats, expressions) and returns a rich AST (Abstract Syntax Tree) on successful match. Grammars can be defined programmatically via classes or declaratively via `.cpat` grammar strings.
|
|
6
|
+
|
|
7
|
+
## What Makes This Parser Different
|
|
8
|
+
|
|
9
|
+
Most parsers force you to choose between **recursive descent** (readable, composable, but can't handle left recursion) and **Pratt/precedence parsing** (handles operator precedence naturally, but requires a different mental model with binding power numbers and nud/led functions). This parser eliminates that tradeoff entirely.
|
|
10
|
+
|
|
11
|
+
When you write what looks like simple recursive options:
|
|
12
|
+
|
|
13
|
+
```
|
|
14
|
+
mul-expr = expr + " * " + expr
|
|
15
|
+
add-expr = expr + " + " + expr
|
|
16
|
+
expr = mul-expr | add-expr | integer
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The grammar system detects the self-references at build time, auto-classifies each alternative as atom, prefix, postfix, or infix, and silently swaps in a Pratt precedence parser — while everything else stays recursive descent. Precedence is determined by declaration order (first = highest). You never need to manually eliminate left recursion, define precedence tables, or restructure your grammar.
|
|
20
|
+
|
|
21
|
+
Compare this to what traditional recursive descent requires to avoid left recursion:
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
# What you're forced to write in most parsers:
|
|
25
|
+
expr = term + addTail
|
|
26
|
+
addTail = "+" + term + addTail | empty
|
|
27
|
+
term = factor + mulTail
|
|
28
|
+
mulTail = "*" + factor + mulTail | empty
|
|
29
|
+
factor = integer | "(" + expr + ")"
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
That grammar no longer resembles the language it describes. With Clarity Pattern Parser, you stay in one mental model everywhere — literals, sequences, options, and expressions all use the same intuitive syntax. Someone can write a full expression grammar with precedence, associativity, prefix, postfix, and grouping that looks almost identical to the BNF you'd find in a language spec.
|
|
33
|
+
|
|
34
|
+
## Modular Grammar Composition
|
|
35
|
+
|
|
36
|
+
Most parser generators treat grammars as monolithic single files. ANTLR has `import` but it's just grammar inheritance. PEG.js/Peggy and Tree-sitter have no import system at all. Nearley has `@include`, which is text concatenation.
|
|
37
|
+
|
|
38
|
+
Clarity Pattern Parser has a full module system closer to how programming languages handle imports:
|
|
39
|
+
|
|
40
|
+
- **Selective imports**: `import { just-this } from "file.cpat"` — pick only the patterns you need
|
|
41
|
+
- **Aliasing**: `import { value as my-value }` — rename on import to avoid collisions
|
|
42
|
+
- **Parameterized grammars**: `import { items } from "list.cpat" with params { separator = "," }` — inject patterns into imported grammars
|
|
43
|
+
- **Default parameters**: `use params { value = default-value }` — fallbacks when no param is supplied
|
|
44
|
+
- **User-controlled resolution**: the `resolveImport` callback means grammars can live anywhere — filesystem, network, database, or bundled strings
|
|
45
|
+
|
|
46
|
+
The parameter system is what makes this truly unique. You can write a generic `delimited-list.cpat` once and import it everywhere with different separators, item patterns, and bounds. A `string.cpat` could accept a quote character as a parameter. A `block.cpat` could accept open/close delimiters. Grammars become reusable components rather than copy-paste templates.
|
|
47
|
+
|
|
48
|
+
## Built-in Grammar Introspection
|
|
49
|
+
|
|
50
|
+
Most parsers have a hard wall between grammar definition and execution — once built, you can't inspect what the grammar expects at runtime. ANTLR gives you flat token vocabulary lists after compilation. PEG.js compiles to a black-box function with no introspection API. Tree-sitter lets you query the output AST but not the grammar structure. Nearley exposes internal Earley chart state, but it's not designed for consumption.
|
|
51
|
+
|
|
52
|
+
Clarity Pattern Parser makes introspection a first-class part of the pattern interface. Every pattern in the tree implements:
|
|
53
|
+
|
|
54
|
+
- `getTokens()` — what literal tokens could this pattern match right now?
|
|
55
|
+
- `getNextTokens()` — what tokens could follow after this pattern completes?
|
|
56
|
+
- `getPatterns()` — what pattern objects are expected at this position?
|
|
57
|
+
- `getNextPatterns()` — what patterns could follow after this one?
|
|
58
|
+
- `getPatternsAfter(child)` — given a specific matched child, what comes next?
|
|
59
|
+
|
|
60
|
+
This isn't bolted on — it's woven into every pattern type with context-aware forwarding. A Sequence knows to ask its parent for next tokens when its last child completes. An Expression knows to suggest postfix and infix tokens after an atom matches. An Optional knows to include both its own tokens and its next sibling's.
|
|
61
|
+
|
|
62
|
+
This powers the `AutoComplete` system — real grammar-aware suggestions at any cursor position, not just keyword lists. Most editors that provide autocomplete for custom languages have to build that infrastructure entirely separate from the parser. Here it's intrinsic to the pattern tree itself.
|
|
63
|
+
|
|
64
|
+
## Extensible Decorators
|
|
65
|
+
|
|
66
|
+
Most parsers handle pattern-level configuration outside the grammar definition. ANTLR has `@header` and `@members` for injecting code into the generated parser, but nothing that annotates individual rules. PEG.js/Peggy attaches JavaScript action blocks `{ return ... }` — powerful but messy inline code, not declarative metadata. Tree-sitter has `prec()` / `prec.left()` function calls in its JavaScript DSL, but those are limited to precedence. Nearley has per-rule postprocessors, which are again inline code.
|
|
67
|
+
|
|
68
|
+
Clarity Pattern Parser takes a declarative approach:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
@tokens([" ", "\t"])
|
|
72
|
+
whitespace = /\s+/
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The grammar stays clean. The decorator is metadata *about* the pattern, not code *inside* the pattern. And it's extensible — you pass custom decorator functions via options and they receive the pattern object to modify however you need:
|
|
76
|
+
|
|
77
|
+
```typescript
|
|
78
|
+
const patterns = createPatternsTemplate({
|
|
79
|
+
decorators: {
|
|
80
|
+
record: (pattern) => { /* modify pattern */ },
|
|
81
|
+
config: (pattern, arg) => { /* arg is JSON-parsed */ }
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
This is a clean plugin point for grammar-level concerns without polluting pattern definitions. Custom decorators can accept JSON arguments — arrays, objects, strings, numbers — keeping everything declarative while remaining open to any use case.
|
|
87
|
+
|
|
88
|
+
## Project Structure
|
|
89
|
+
|
|
90
|
+
```
|
|
91
|
+
src/
|
|
92
|
+
ast/
|
|
93
|
+
Node.ts # AST node class (the parse output)
|
|
94
|
+
compact.ts # Collapse subtrees into single value nodes
|
|
95
|
+
remove.ts # Remove nodes from tree
|
|
96
|
+
patterns/
|
|
97
|
+
Pattern.ts # Pattern interface (all patterns implement this)
|
|
98
|
+
Literal.ts # Exact string match
|
|
99
|
+
Regex.ts # Regular expression match
|
|
100
|
+
Sequence.ts # Ordered concatenation (AND)
|
|
101
|
+
Options.ts # Alternatives (OR)
|
|
102
|
+
Expression.ts # Operator precedence parsing (recursive expressions)
|
|
103
|
+
Repeat.ts # Repetition with bounds and dividers
|
|
104
|
+
InfiniteRepeat.ts # Unbounded repetition implementation
|
|
105
|
+
FiniteRepeat.ts # Bounded repetition implementation
|
|
106
|
+
Optional.ts # Zero-or-one match
|
|
107
|
+
Not.ts # Negative lookahead
|
|
108
|
+
TakeUntil.ts # Consume text until terminator pattern
|
|
109
|
+
Reference.ts # Named reference to another pattern (enables recursion)
|
|
110
|
+
Context.ts # Scoped pattern resolution (wraps each grammar pattern)
|
|
111
|
+
RightAssociated.ts # Marks a pattern as right-associative in Expressions
|
|
112
|
+
Cursor.ts # Text traversal state (position, grapheme-aware)
|
|
113
|
+
CursorHistory.ts # Match/error recording for debugging and intellisense
|
|
114
|
+
ParseError.ts # Error position and pattern info
|
|
115
|
+
ParseResult.ts # { ast: Node | null, cursor: Cursor }
|
|
116
|
+
PrecedenceTree.ts # Builds precedence-correct AST for Expression
|
|
117
|
+
execPattern.ts # Main execution: creates Cursor, runs parse, checks full match
|
|
118
|
+
testPattern.ts # Boolean test: did the pattern match the full text?
|
|
119
|
+
grammar/
|
|
120
|
+
Grammar.ts # Parses .cpat grammar strings into Pattern objects
|
|
121
|
+
patterns.ts # Tagged template literal API: patterns`...`
|
|
122
|
+
patterns/
|
|
123
|
+
grammar.ts # The grammar pattern itself (bootstrapped)
|
|
124
|
+
body.ts # Body section of grammar (statements)
|
|
125
|
+
statement.ts # Assignment statements
|
|
126
|
+
pattern.ts # Right-hand side pattern dispatch
|
|
127
|
+
literal.ts # "string" literals in grammar
|
|
128
|
+
regexLiteral.ts # /regex/ literals in grammar
|
|
129
|
+
sequenceLiteral.ts # a + b + c sequences in grammar
|
|
130
|
+
optionsLiteral.ts # a | b | c options in grammar
|
|
131
|
+
repeatLiteral.ts # (pattern){n,m} repeats in grammar
|
|
132
|
+
takeUtilLiteral.ts # ?->| pattern take-until in grammar
|
|
133
|
+
anonymousPattern.ts# Inline anonymous patterns in grammar
|
|
134
|
+
import.ts # import/use params statements in grammar
|
|
135
|
+
comment.ts # # comments in grammar
|
|
136
|
+
spaces.ts # Whitespace patterns
|
|
137
|
+
decorators/
|
|
138
|
+
tokens.ts # @tokens decorator implementation
|
|
139
|
+
intellisense/
|
|
140
|
+
AutoComplete.ts # Autocomplete suggestions from pattern structure
|
|
141
|
+
Suggestion.ts # Suggestion result type
|
|
142
|
+
query/
|
|
143
|
+
selector.ts # CSS-like selectors for AST querying
|
|
144
|
+
query.ts # Query API for AST
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
## Core Architecture
|
|
148
|
+
|
|
149
|
+
### Pattern Hierarchy
|
|
150
|
+
|
|
151
|
+
Every parser component implements the `Pattern` interface:
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
Pattern (interface)
|
|
155
|
+
parse(cursor: Cursor): Node | null # Core parsing method
|
|
156
|
+
exec(text: string): ParseResult # Convenience: parse full text
|
|
157
|
+
test(text: string): boolean # Convenience: boolean match
|
|
158
|
+
clone(name?): Pattern # Deep copy
|
|
159
|
+
getTokens(): string[] # Intellisense support
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
**Leaf Patterns** (match text directly):
|
|
163
|
+
- `Literal` - exact string match, type = `"literal"`
|
|
164
|
+
- `Regex` - regex match (auto-prepends `^`, uses `gu` flags), type = `"regex"`
|
|
165
|
+
|
|
166
|
+
**Composite Patterns** (compose other patterns):
|
|
167
|
+
- `Sequence` - all children must match in order, type = `"sequence"`
|
|
168
|
+
- `Options` - first matching child wins (or longest if greedy), type = `"options"`
|
|
169
|
+
- `Expression` - operator precedence with prefix/postfix/infix, type = `"expression"`
|
|
170
|
+
- `Repeat` - bounded repetition with optional divider, type = `"infinite-repeat"` or `"finite-repeat"`
|
|
171
|
+
|
|
172
|
+
**Modifier Patterns** (wrap another pattern):
|
|
173
|
+
- `Optional` - match or skip (0 or 1), type = `"optional"`
|
|
174
|
+
- `Not` - negative lookahead (fails if child matches), type = `"not"`
|
|
175
|
+
- `TakeUntil` - consume all text until terminator matches, type = `"take-until"`
|
|
176
|
+
- `Reference` - lazy name-based lookup (enables recursion), type = `"reference"`
|
|
177
|
+
- `Context` - scoped resolution for references, type = `"context"`
|
|
178
|
+
- `RightAssociated` - marks infix pattern as right-associative, type = `"right-associated"`
|
|
179
|
+
|
|
180
|
+
### Parsing Flow
|
|
181
|
+
|
|
182
|
+
1. **Input**: Text string to parse
|
|
183
|
+
2. **Cursor creation**: `new Cursor(text)` - tracks position, grapheme-aware
|
|
184
|
+
3. **Pattern.parse(cursor)**: Recursive descent
|
|
185
|
+
- Leaf patterns compare text at cursor position, create leaf `Node`
|
|
186
|
+
- Composite patterns orchestrate children, create parent `Node` with child nodes
|
|
187
|
+
- On failure: returns `null`, records error on cursor
|
|
188
|
+
- On success: returns `Node`, advances cursor
|
|
189
|
+
4. **Full match check**: `execPattern()` verifies the entire input was consumed
|
|
190
|
+
5. **Result**: `ParseResult { ast: Node | null, cursor: Cursor }`
|
|
191
|
+
|
|
192
|
+
### Expression Pattern (Pratt Parsing)
|
|
193
|
+
|
|
194
|
+
The `Expression` pattern handles operator precedence automatically. When the grammar defines an options pattern where some alternatives reference the pattern itself (recursive), it becomes an `Expression` instead of `Options`.
|
|
195
|
+
|
|
196
|
+
Patterns are auto-classified:
|
|
197
|
+
- **Atoms**: No self-reference (e.g., `integer`, `group`)
|
|
198
|
+
- **Prefix**: Self-reference only at end (e.g., `unary-operator + expr`)
|
|
199
|
+
- **Postfix**: Self-reference only at start (e.g., `expr + postfix-operator`)
|
|
200
|
+
- **Infix/Binary**: Self-reference at both ends (e.g., `expr + operator + expr`)
|
|
201
|
+
|
|
202
|
+
Precedence is determined by declaration order (first = highest precedence). Association defaults to left; use `right` keyword or `RightAssociated` wrapper for right-associativity.
|
|
203
|
+
|
|
204
|
+
### Grammar System
|
|
205
|
+
|
|
206
|
+
The `Grammar` class parses `.cpat` grammar definition strings into `Pattern` objects. The grammar syntax itself is bootstrapped - it's defined using the same Pattern classes it produces.
|
|
207
|
+
|
|
208
|
+
**Flow**:
|
|
209
|
+
1. Grammar text is parsed by the internal `grammar` pattern (self-hosted)
|
|
210
|
+
2. The resulting AST is walked to build `Pattern` objects
|
|
211
|
+
3. Each named pattern is wrapped in a `Context` for reference resolution
|
|
212
|
+
4. Returns `Record<string, Pattern>` - all named patterns accessible by name
|
|
213
|
+
|
|
214
|
+
### Context and Reference Resolution
|
|
215
|
+
|
|
216
|
+
When a grammar pattern references another pattern by name, it creates a `Reference`. At parse time, `Reference` walks up the pattern tree to find a `Context` that contains the target pattern. `Context` wraps every top-level grammar pattern and holds all sibling patterns for resolution.
|
|
217
|
+
|
|
218
|
+
This enables:
|
|
219
|
+
- Forward references (use a pattern before defining it)
|
|
220
|
+
- Recursive patterns (a pattern that references itself)
|
|
221
|
+
- Imported patterns (resolved at grammar parse time)
|
|
222
|
+
|
|
223
|
+
### AST Node
|
|
224
|
+
|
|
225
|
+
The `Node` class is the output of all parsing. It forms a tree structure:
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
Node {
|
|
229
|
+
type: string // Pattern type that created it ("literal", "regex", "sequence", etc.)
|
|
230
|
+
name: string // Pattern name (user-defined in grammar)
|
|
231
|
+
value: string // Matched text (computed from children for composite nodes)
|
|
232
|
+
startIndex: number // 0-based start position in input
|
|
233
|
+
endIndex: number // 0-based exclusive end position
|
|
234
|
+
children: Node[] // Child nodes (empty for leaf nodes)
|
|
235
|
+
parent: Node // Parent reference
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
Key methods: `find()`, `findAll()`, `walkUp()`, `walkDown()`, `transform()`, `flatten()`, `compact()`, `remove()`, `clone()`, `toCycleFreeObject()`, `toJson()`.
|
|
240
|
+
|
|
241
|
+
### Two APIs for Grammar Definition
|
|
242
|
+
|
|
243
|
+
**1. Programmatic API** - Build patterns directly with classes:
|
|
244
|
+
```typescript
|
|
245
|
+
const name = new Literal("name", "John");
|
|
246
|
+
const pattern = new Sequence("greeting", [new Literal("hi", "Hello "), name]);
|
|
247
|
+
const result = pattern.exec("Hello John");
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
**2. Grammar String API** - Define patterns declaratively:
|
|
251
|
+
```typescript
|
|
252
|
+
// Via Grammar class
|
|
253
|
+
const patterns = Grammar.parseString(`
|
|
254
|
+
name = "John"
|
|
255
|
+
greeting = "Hello " + name
|
|
256
|
+
`);
|
|
257
|
+
const result = patterns["greeting"].exec("Hello John");
|
|
258
|
+
|
|
259
|
+
// Via tagged template literal (kebab-case names become camelCase)
|
|
260
|
+
const { greeting } = patterns`
|
|
261
|
+
name = "John"
|
|
262
|
+
greeting = "Hello " + name
|
|
263
|
+
`;
|
|
264
|
+
const result = greeting.exec("Hello John");
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Import System
|
|
268
|
+
|
|
269
|
+
Grammars support importing patterns from other `.cpat` files:
|
|
270
|
+
```
|
|
271
|
+
import { pattern-name } from "path/to/file.cpat"
|
|
272
|
+
import { old-name as new-name } from "file.cpat"
|
|
273
|
+
import { pattern } from "file.cpat" with params { key = value }
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Import resolution is user-provided via `resolveImport` / `resolveImportSync` callbacks.
|
|
277
|
+
|
|
278
|
+
### Parameterized Grammars
|
|
279
|
+
|
|
280
|
+
Grammars can accept parameters, allowing pattern injection:
|
|
281
|
+
```
|
|
282
|
+
use params { custom-divider }
|
|
283
|
+
items = (item, custom-divider)+
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
Parameters are passed via the `params` option or through `with params` blocks in import statements.
|
|
287
|
+
|
|
288
|
+
### Decorators
|
|
289
|
+
|
|
290
|
+
Patterns can be decorated in grammar files:
|
|
291
|
+
```
|
|
292
|
+
@tokens([" ", "\t"])
|
|
293
|
+
whitespace = /\s+/
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
The `@tokens` decorator is built-in. Custom decorators are supported via the `decorators` option.
|
|
297
|
+
|
|
298
|
+
### Intellisense
|
|
299
|
+
|
|
300
|
+
Every pattern implements `getTokens()`, `getNextTokens()`, `getPatterns()`, and `getNextPatterns()`. The `AutoComplete` class uses these to provide context-aware suggestions at any position in a partial parse.
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { Pattern } from "../patterns/Pattern";
|
|
2
|
-
export type Decorator = (pattern: Pattern, arg?: string | boolean | number | null | Record<string, any> | any[]) => void;
|
|
3
1
|
export interface GrammarFile {
|
|
4
2
|
resource: string;
|
|
5
3
|
expression: string;
|
|
6
4
|
}
|
|
5
|
+
import { Pattern } from "../patterns/Pattern";
|
|
6
|
+
export type Decorator = (pattern: Pattern, arg?: string | boolean | number | null | Record<string, any> | any[]) => void;
|
|
7
7
|
export interface GrammarOptions {
|
|
8
8
|
resolveImport?: (resource: string, originResource: string | null) => Promise<GrammarFile>;
|
|
9
9
|
resolveImportSync?: (resource: string, originResource: string | null) => GrammarFile;
|
|
@@ -12,47 +12,46 @@ export interface GrammarOptions {
|
|
|
12
12
|
decorators?: Record<string, Decorator>;
|
|
13
13
|
}
|
|
14
14
|
export declare class Grammar {
|
|
15
|
+
private _options;
|
|
16
|
+
private _parseContext;
|
|
15
17
|
private _params;
|
|
16
18
|
private _originResource?;
|
|
17
19
|
private _resolveImport;
|
|
18
20
|
private _resolveImportSync;
|
|
19
|
-
private _parseContext;
|
|
20
21
|
constructor(options?: GrammarOptions);
|
|
21
22
|
import(path: string): Promise<Record<string, Pattern>>;
|
|
22
23
|
parse(expression: string): Promise<Record<string, Pattern>>;
|
|
23
24
|
parseString(expression: string): Record<string, Pattern>;
|
|
24
|
-
|
|
25
|
+
static parse(expression: string, options?: GrammarOptions): Promise<Record<string, Pattern>>;
|
|
26
|
+
static import(path: string, options?: GrammarOptions): Promise<Record<string, Pattern>>;
|
|
27
|
+
static parseString(expression: string, options?: GrammarOptions): Record<string, Pattern>;
|
|
25
28
|
private _tryToParse;
|
|
26
|
-
private
|
|
29
|
+
private _flattenExpressionsRecursive;
|
|
30
|
+
private _unwrapNode;
|
|
31
|
+
private _buildPatternRecord;
|
|
27
32
|
private _buildPatterns;
|
|
28
|
-
private
|
|
33
|
+
private _buildPattern;
|
|
29
34
|
private _buildLiteral;
|
|
30
|
-
private _resolveStringValue;
|
|
31
|
-
private _saveRegex;
|
|
32
35
|
private _buildRegex;
|
|
33
|
-
private _saveOptions;
|
|
34
|
-
private _buildOptions;
|
|
35
|
-
private _isRecursive;
|
|
36
|
-
private _isRecursivePattern;
|
|
37
|
-
private _buildPattern;
|
|
38
|
-
private _saveSequence;
|
|
39
36
|
private _buildSequence;
|
|
40
|
-
private
|
|
37
|
+
private _buildOptions;
|
|
38
|
+
private _buildGreedyOptions;
|
|
41
39
|
private _buildRepeat;
|
|
42
|
-
private
|
|
40
|
+
private _buildPatternGroup;
|
|
41
|
+
private _buildNot;
|
|
42
|
+
private _buildOptional;
|
|
43
|
+
private _buildRightAssociation;
|
|
43
44
|
private _buildTakeUntil;
|
|
44
|
-
private
|
|
45
|
-
private
|
|
45
|
+
private _resolveStringValue;
|
|
46
|
+
private _getPattern;
|
|
47
|
+
private _isRecursive;
|
|
48
|
+
private _isRecursivePattern;
|
|
49
|
+
private _applyDecorators;
|
|
46
50
|
private _resolveImports;
|
|
47
51
|
private _resolveImportsSync;
|
|
48
52
|
private _processImportSync;
|
|
49
53
|
private _processImport;
|
|
54
|
+
private _processImportNames;
|
|
55
|
+
private _getWithParams;
|
|
50
56
|
private _processUseParams;
|
|
51
|
-
private _applyDecorators;
|
|
52
|
-
private _getParams;
|
|
53
|
-
private _getPattern;
|
|
54
|
-
private _saveAlias;
|
|
55
|
-
static parse(expression: string, options?: GrammarOptions): Promise<Record<string, Pattern>>;
|
|
56
|
-
static import(path: string, options?: GrammarOptions): Promise<Record<string, Pattern>>;
|
|
57
|
-
static parseString(expression: string, options?: GrammarOptions): Record<string, Pattern>;
|
|
58
57
|
}
|
|
@@ -1,2 +1,101 @@
|
|
|
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";
|
|
1
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 anyChar: Literal;
|
|
32
|
+
export declare const upTo: Literal;
|
|
33
|
+
export declare const wall: Literal;
|
|
34
|
+
export declare const asKeyword: Literal;
|
|
35
|
+
export declare const newLine: Regex;
|
|
36
|
+
export declare const syntaxVersion: Regex;
|
|
37
|
+
export declare const at: Literal;
|
|
38
|
+
export declare const optionalWS: Optional;
|
|
39
|
+
export declare const optionalLS: Optional;
|
|
40
|
+
export declare const literal: Regex;
|
|
41
|
+
export declare const regex: Regex;
|
|
42
|
+
export declare const integer: Regex;
|
|
43
|
+
export declare const name: Regex;
|
|
44
|
+
export declare const patternName: Regex;
|
|
45
|
+
export declare const patternIdentifier: Regex;
|
|
46
|
+
export declare const resource: Regex;
|
|
47
|
+
export declare const comment: Regex;
|
|
48
|
+
export declare const jsonString: Regex;
|
|
49
|
+
export declare const jsonNumber: Regex;
|
|
50
|
+
export declare const trueLiteral: Literal;
|
|
51
|
+
export declare const falseLiteral: Literal;
|
|
52
|
+
export declare const jsonBoolean: Options;
|
|
53
|
+
export declare const jsonNull: Literal;
|
|
54
|
+
export declare const jsonArrayItems: Repeat;
|
|
55
|
+
export declare const jsonArray: Sequence;
|
|
56
|
+
export declare const jsonObjectPropertyName: Regex;
|
|
57
|
+
export declare const jsonObjectProperty: Sequence;
|
|
58
|
+
export declare const jsonObjectProperties: Repeat;
|
|
59
|
+
export declare const jsonObject: Sequence;
|
|
60
|
+
export declare const jsonValue: Options;
|
|
61
|
+
export declare const syntaxStatement: Sequence;
|
|
62
|
+
export declare const decorationName: Regex;
|
|
63
|
+
export declare const methodDecorationStatement: Sequence;
|
|
64
|
+
export declare const nameDecorationStatement: Sequence;
|
|
65
|
+
export declare const decorationStatement: Options;
|
|
66
|
+
export declare const defaultParamName: Regex;
|
|
67
|
+
export declare const paramDefault: Sequence;
|
|
68
|
+
export declare const paramNameWithDefault: Sequence;
|
|
69
|
+
export declare const useParamPatterns: Repeat;
|
|
70
|
+
export declare const useParamsStatement: Sequence;
|
|
71
|
+
export declare const withParamExportPattern: Regex;
|
|
72
|
+
export declare const withParamStatement: Options;
|
|
73
|
+
export declare const withParamStatements: Repeat;
|
|
74
|
+
export declare const withParamsExpr: Sequence;
|
|
75
|
+
export declare const importNameAlias: Regex;
|
|
76
|
+
export declare const importAlias: Sequence;
|
|
77
|
+
export declare const importNameOrAlias: Options;
|
|
78
|
+
export declare const patternNames: Repeat;
|
|
79
|
+
export declare const importedPatterns: Sequence;
|
|
80
|
+
export declare const importStatement: Sequence;
|
|
81
|
+
export declare const repeatBounds: Sequence;
|
|
82
|
+
export declare const oneOrMore: Literal;
|
|
83
|
+
export declare const zeroOrMore: Literal;
|
|
84
|
+
export declare const repeatOptions: Options;
|
|
85
|
+
export declare const delimiter: Sequence;
|
|
86
|
+
export declare const repeatExpr: Sequence;
|
|
87
|
+
export declare const takeUntilExpr: Sequence;
|
|
88
|
+
export declare const sequenceExpr: Sequence;
|
|
89
|
+
export declare const optionsExpr: Sequence;
|
|
90
|
+
export declare const greedyOptionsExpr: Sequence;
|
|
91
|
+
export declare const patternGroupExpr: Sequence;
|
|
92
|
+
export declare const notExpr: Sequence;
|
|
93
|
+
export declare const optionalExpr: Sequence;
|
|
94
|
+
export declare const rightAssociationExpr: Sequence;
|
|
95
|
+
export declare const exportPattern: Regex;
|
|
96
|
+
export declare const patternExpr: Expression;
|
|
97
|
+
export declare const patternAssignment: Sequence;
|
|
98
|
+
export declare const statement: Options;
|
|
99
|
+
export declare const statements: Repeat;
|
|
100
|
+
export declare const cpat: Sequence;
|
|
2
101
|
export declare const grammar: Sequence;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|