/** * Parser module for TabScript transpiler. * Contains the Parser class with all parsing methods. * * @module parser */ import { State } from './state.js'; import type { Options } from './tabscript.js'; /** * Signature for parser methods that can be extended by plugins. * Methods must return truthy on success, falsy on failure. * On failure, the state must be left unchanged. */ export type ParserMethod = (this: Parser, s: State, ...args: any[]) => boolean | string; /** * TabScript parser implementing recursive descent parsing. * * All `parse*` methods follow a contract: * - Return truthy on success, falsy on failure * - On failure, leave the state unchanged * * Plugins can modify `parse*` methods directly on the Parser instance. */ export declare class Parser { options: Options; constructor(options: Options); /** * Creates a token matcher regex with a descriptive name for error messages. * Automatically adds the sticky (/y) flag if not present. * * This is the recommended way to create regex patterns for use with * `s.read()`, `s.accept()`, `s.peek()`, and related methods in plugins. * * @param regexp - The regular expression pattern to match tokens * @param name - A descriptive name shown in error messages (e.g., "identifier", "number") * @returns A new RegExp with the sticky flag and custom toString() */ pattern(regexp: RegExp, name: string): RegExp; /** * Parse function parameters. * @example `|a, b: number, c = 3|` or `(a, b: number, c = 3)` */ parseFuncParams(s: State, isConstructor?: boolean, parenthesis?: boolean): boolean | string; /** * Parse a function definition. * @example `|x| x * 2` or `async |x| await fetch(x)` or `function foo|x| x * 2` */ parseFunction(s: State, declaration?: boolean): boolean; /** * Parse a variable declaration. * @example `x := 5` (const) or `x ::= 5` (let) or `x: number := 5` (with type) */ parseVarDecl(s: State, allowInit?: boolean): boolean; /** * Parse an expression. * @example `x + 1` or `foo(bar)` or `obj.method.. arg1 arg2` */ parseExpression(s: State, withinTag?: boolean): boolean; /** * Parse a type annotation. * @example `number` or `string[]` or `{x: number, y: string}` or `Foo` */ parseType(s: State, allowFunction?: boolean): boolean; /** * Parse a class method or property. * @example `myMethod|x| x * 2` or `static count := 0` or `get name|| this._name` */ parseMethod(s: State, typeOnly?: boolean, isDerived?: boolean): boolean; /** * Parse a class or interface definition. * @example `class Foo extends Bar` or `interface IFoo` or `abstract class Base` */ parseClass(s: State): boolean; /** * Parse the main entry point - processes header and all statements. */ parseMain(s: State): boolean; /** * Parse the TabScript header line. * Header format: tabscript X.Y */ parseHeader(s: State): boolean; /** * Parse a single statement. * @example `x := 5` or `if condition` or `for item: of items` or `return value` */ parseStatement(s: State): boolean | string; parseExport(s: State): boolean; parseTypeDecl(s: State): boolean; parseEnum(s: State): boolean; parseReturn(s: State): boolean; parseIfWhile(s: State): boolean; parseThrow(s: State): boolean; parseDoWhile(s: State): boolean; parseFor(s: State): boolean; parseSwitch(s: State): boolean; parseImport(s: State): boolean; parseTry(s: State): boolean; parseDeclare(s: State): boolean; parseBlock(s: State): boolean; parseTemplateDef(s: State): boolean; parseClassicFuncExprBody(s: State): boolean; parseArrowFuncExprBody(s: State): boolean; parseFuncType(s: State): boolean; parseParenthesised(s: State): boolean; parseExpressionSeq(s: State): boolean; parseBacktickString(s: State): boolean; parseLiteralArray(s: State): boolean; parseLiteralObject(s: State): boolean; parseTemplateArg(s: State): boolean; parseIndex(s: State): boolean; parseTypeObjectEntry(s: State): boolean; }