import { CharStream, CommonToken, Token, TokenFactory, TokenSource } from "antlr4ng"; import { ErrorManager } from "../misc/ErrorManager.js"; /** * This class represents the tokenizer for templates. It operates in two modes: * inside and outside of expressions. It implements the {@link TokenSource} * interface so it can be used with ANTLR parsers. Outside of expressions, we * can return these token types: {@link #TEXT}, {@link #INDENT}, {@link #LDELIM} * (start of expression), {@link #RCURLY} (end of subtemplate), and * {@link #NEWLINE}. Inside of an expression, this lexer returns all of the * tokens needed by {@link STParser}. From the parser's point of view, it can * treat a template as a simple stream of elements. *

* This class defines the token types and communicates these values to * {@code STParser.g} via {@code STLexer.tokens} file (which must remain * consistent).

*/ export declare class STLexer implements TokenSource { #private; /** * We build {@code STToken} tokens instead of relying on {@link CommonToken} * so we can override {@link #toString()}. It just converts token types to * token names like 23 to {@code "LDELIM"}. */ static STToken: { new (type: number, text: string): { toString(): string; "__#10@#private": any; source: [TokenSource | null, CharStream | null]; tokenIndex: number; start: number; stop: number; type: number; line: number; column: number; channel: number; readonly tokenSource: TokenSource | null; inputStream: CharStream | null; clone(): CommonToken; get text(): string | undefined; set text(text: string); setText(text: string): void; setType(ttype: number): void; setLine(line: number): void; setCharPositionInLine(pos: number): void; setChannel(channel: number): void; setTokenIndex(index: number): void; }; new (tokenSource: TokenSource, input: CharStream, type: number, start: number, stop: number): { toString(): string; "__#10@#private": any; source: [TokenSource | null, CharStream | null]; tokenIndex: number; start: number; stop: number; type: number; line: number; column: number; channel: number; readonly tokenSource: TokenSource | null; inputStream: CharStream | null; clone(): CommonToken; get text(): string | undefined; set text(text: string); setText(text: string): void; setType(ttype: number): void; setLine(line: number): void; setCharPositionInLine(pos: number): void; setChannel(channel: number): void; setTokenIndex(index: number): void; }; readonly EMPTY_SOURCE: [TokenSource | null, CharStream | null]; fromToken(token: Token): CommonToken; fromType(type: number, text?: string): CommonToken; fromSource(source: [TokenSource | null, CharStream | null], type: number, channel: number, start: number, stop: number): CommonToken; }; static readonly SKIP: { toString(): string; "__#10@#private": any; source: [TokenSource | null, CharStream | null]; tokenIndex: number; start: number; stop: number; type: number; line: number; column: number; channel: number; readonly tokenSource: TokenSource | null; inputStream: CharStream | null; clone(): CommonToken; get text(): string | undefined; set text(text: string); setText(text: string): void; setType(ttype: number): void; setLine(line: number): void; setCharPositionInLine(pos: number): void; setChannel(channel: number): void; setTokenIndex(index: number): void; }; static readonly RBRACK = 17; static readonly LBRACK = 16; static readonly ELSE = 5; static readonly ELLIPSIS = 11; static readonly LCURLY = 20; static readonly BANG = 10; static readonly EQUALS = 12; static readonly TEXT = 22; static readonly ID = 25; static readonly SEMI = 9; static readonly LPAREN = 14; static readonly IF = 4; static readonly ELSEIF = 6; static readonly COLON = 13; static readonly RPAREN = 15; static readonly COMMA = 18; static readonly RCURLY = 21; static readonly ENDIF = 7; static readonly RDELIM = 24; static readonly SUPER = 8; static readonly DOT = 19; static readonly LDELIM = 23; static readonly STRING = 26; static readonly PIPE = 28; static readonly OR = 29; static readonly AND = 30; static readonly INDENT = 31; static readonly NEWLINE = 32; static readonly AT = 33; static readonly REGION_END = 34; static readonly TRUE = 35; static readonly FALSE = 36; static readonly COMMENT = 37; static readonly SLASH = 38; /** * To be able to properly track the inside/outside mode, we need to * track how deeply nested we are in some templates. Otherwise, we * know whether a '}' and the outermost subtemplate to send this * back to outside mode. */ subtemplateDepth: number; line: number; _tokenStartColumn: number; sourceName: string; tokenFactory: TokenFactory; inputStream: CharStream; /** The char which delimits the start of an expression. */ protected delimiterStartChar: number; /** The char which delimits the end of an expression. */ protected delimiterStopChar: number; /** * This keeps track of the current mode of the lexer. Are we inside or * outside an ST expression? */ protected scanningInsideExpr: boolean; protected errMgr: ErrorManager; /** template embedded in a group file? this is the template */ protected templateToken: Token | null; /** current character */ protected c: number; /** * When we started token, track initial coordinates so we can properly * build token objects. */ protected startCharIndex: number; /** * Our lexer routines might have to emit more than a single token. We * buffer everything through this list. */ protected tokens: Token[]; constructor(inputOrErrMgr: ErrorManager | CharStream, input?: CharStream, templateToken?: Token, delimiterStartChar?: string, delimiterStopChar?: string); get column(): number; nextToken(): Token; /** Consume if {@code x} is next character on the input stream. */ match(x: number | string): void; emit(token: Token): void; _nextToken(): Token; newToken(tokenType: number, text?: string, pos?: number): Token; newTokenFromPreviousChar(tokenType: number): Token; protected consume(): void; protected outside(): Token; protected inside(): Token; protected subTemplate(): Token; protected matchESCAPE(): Token; protected matchHexNumber(): Token; protected matchTEXT(): Token; /** *
     *  ID  : ('a'..'z'|'A'..'Z'|'_'|'/')
     *        ('a'..'z'|'A'..'Z'|'0'..'9'|'_'|'/')*
     *      ;
     *  
* * @returns A token representing the matched ID. */ protected mID(): Token; /** *
     *  STRING : '"'
     *           (   '\\' '"'
     *           |   '\\' ~'"'
     *           |   ~('\\'|'"')
     *           )*
     *           '"'
     *         ;
     * 
* * @returns A token representing the matched string. */ protected mSTRING(): Token; protected matchWS(): void; protected matchCOMMENT(): Token; protected matchLINEBREAK(): void; /** * @returns `true` if the current char matches any of the given alternatives */ private currentCharMatchesOneOf; /** * @returns `true` if the current char is a hex digit */ private currentCharIsHexDigit; /** * @returns `true` if the current char can be used as first letter for an identifier. */ private currentCharIsIDStartLetter; /** * @returns `true` if the current char can be used in an identifier. */ private currentCharIsIDLetter; /** * @returns A string representation of the current char. */ private currentCharToString; private lexerError; }