import CodeFile from "./CodeFile"; import CodeLocation from "./CodeLocation"; import ErrorCollector from "./ErrorCollector"; import { ExtraToken } from "./extraTokens"; import Token from "./Token"; import TokenType from "./TokenType"; /** * The lexer is responsible for turning a string of characters into a stream of * tokens. The tokens are then used by the parser to build an abstract syntax * tree. * * The lexer handles parsing of string literals, digraphs (e.g. `<=`), and numbers. * It also handles detecting keywords and identifiers. */ export default class Lexer { codeFile: CodeFile; errorCollector: ErrorCollector; protected start: CodeLocation; protected startWithWhitespace: CodeLocation; tokens: Token[]; protected currentExtraTokens: ExtraToken[]; protected charOffset: number; protected lineOffset: number; protected colOffset: number; protected _currLocCache: CodeLocation | null; constructor(codeFile: CodeFile, errorCollector: ErrorCollector); /** * Scans the whole CodeFile and splits it into tokens. * @throws LexingError */ scan(): Token[]; protected scanToken(): void; protected consumeStringLiteral(): void; protected consumeNumberLiteral(): void; protected consumeIdentifierOrKeyword(): void; protected consumeNumberOrIdentifierOrKeyword(): void; protected consumeFileNameInChevrons(): void; /** * Adds a token to the token list. If a value is provieded a LiteralToken is pushed. * * Additionally it handles clearing and attaching the extra tokens. */ protected addToken(tokenType: TokenType, value?: TValue | null): void; protected isAtEnd(): boolean; protected match(expected: string): boolean; protected advance(): string; protected getLoc(): CodeLocation; protected peek(): string; protected peekNext(): string; protected peekRegex(regex: RegExp): string; }