@scinorandex/slex
Version:
No fuss lexer generator
59 lines (58 loc) • 1.99 kB
TypeScript
export declare class RegexEngineParsingResult {
success: boolean;
lexeme: string;
from: string | null;
constructor(success: boolean, lexeme: string, from: string | null);
toString(): string;
}
export type StringTransformer = (input: string) => string;
export declare abstract class RegexNode<TokenType> {
private emit;
private transformer;
getTokenType(): TokenType | null;
setTokenType(emit: TokenType): void;
getTransformer(): StringTransformer | null;
setTransformer(transformer: StringTransformer): void;
abstract toString(): String;
abstract getMatches(restString: string, environment: Map<string, RegexNode<TokenType>>, negated: boolean): string[];
}
export declare class RegexIntrinsicNode<TokenType> extends RegexNode<TokenType> {
readonly intrinsicName: string;
readonly calculator: (restString: string, environment: Map<string, RegexNode<TokenType>>) => string[];
constructor(intrinsicName: string, calculator: (restString: string, environment: Map<string, RegexNode<TokenType>>) => string[]);
toString(): string;
getMatches(restString: string, environment: Map<string, RegexNode<TokenType>>): string[];
}
export declare class RegexParser<TokenType> {
tokens: RegexToken[];
currentTokenIndex: number;
constructor(tokens: RegexToken[]);
parse(): RegexNode<TokenType>;
parseConcatenation(): RegexNode<TokenType>;
parseTerminal(): RegexNode<TokenType>;
expect(type: RegexTokenType): void;
}
declare enum RegexTokenType {
LITERAL = 0,
PIPE = 1,
ASTERISK = 2,
EXCLAMATION = 3,
PLUS = 4,
VARIABLE = 5,
LPAREN = 6,
RPAREN = 7
}
declare class RegexToken {
type: RegexTokenType;
value: string;
constructor(type: RegexTokenType, value: string);
toString(): string;
}
export declare class RegexLexer {
expression: string;
tokens: RegexToken[];
index: number;
constructor(expression: string);
lex(): RegexToken[];
}
export {};