Skip to content

Commit f810220

Browse files
committed
fix(types): provide TypeScript type for Grammar
1 parent 51fa240 commit f810220

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

types/index.d.ts

+26
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,33 @@ interface ResolveOptions {
2121
encoder: (paramterValue: string, parameterName?: string) => string;
2222
}
2323

24+
export interface Grammar {
25+
grammarObject: string; // Internal identifier
26+
rules: Rule[]; // List of grammar rules
27+
udts: UDT[]; // User-defined terminals (empty in this grammar)
28+
toString(): string; // Method to return the grammar in ABNF format
29+
}
30+
31+
export interface Rule {
32+
name: string; // Rule name
33+
lower: string; // Lowercased rule name
34+
index: number; // Rule index
35+
isBkr: boolean; // Is this a back-reference?
36+
opcodes?: Opcode[]; // List of opcodes for the rule
37+
}
38+
39+
export type Opcode =
40+
| { type: 1; children: number[] } // ALT (alternation)
41+
| { type: 2; children: number[] } // CAT (concatenation)
42+
| { type: 3; min: number; max: number } // REP (repetition)
43+
| { type: 4; index: number } // RNM (rule reference)
44+
| { type: 5; min: number; max: number } // TRG (terminal range)
45+
| { type: 6 | 7; string: number[] }; // TBS or TLS (byte sequence or literal string)
46+
47+
export type UDT = {}; // User-defined terminals (empty in this grammar)
48+
2449
export function parse(pathTemplate: string): ParseResult;
2550
export function test(pathTemplate: string, options?: TestOptions): boolean;
2651
export function resolve(pathTemplate: string, parameters: Parameters, options?: ResolveOptions): string;
2752
export function encodePathComponent(parameterValue: string): string;
53+
export function Grammar(): Grammar;

0 commit comments

Comments
 (0)