Skip to content

Commit 41710e7

Browse files
committed
fix(types): provide TypeScript type for Grammar
1 parent 5202e27 commit 41710e7

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

types/index.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ interface SubstituteOptions {
2020
encoder: (serverVariableValue: string, serverVariableName?: string) => string;
2121
}
2222

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

0 commit comments

Comments
 (0)