import AssignmentNode, { AssignmentNodeRole } from "./ast/AssignmentNode"; import ErrorNode from "./ast/ErrorNode"; import { AnonymousFunctionExpr, Expression } from "./ast/expressions"; import ScadFile from "./ast/ScadFile"; import { BlockStmt, FunctionDeclarationStmt, IfElseStatement, IncludeStmt, ModuleDeclarationStmt, ModuleInstantiationStmt, NoopStmt, UseStmt } from "./ast/statements"; import CodeFile from "./CodeFile"; import CodeLocation from "./CodeLocation"; import ErrorCollector from "./ErrorCollector"; import ParsingError from "./errors/ParsingError"; import Token from "./Token"; import TokenType from "./TokenType"; export default class Parser { protected currentToken: number; /** * The code file being parsed. */ code: CodeFile; /** * The tokens being parsed. They have to be provided from the lexer * @see [[Lexer.scan]] */ tokens: Token[]; /** * The ErrorCollector for this parser. All the errors encountered by the parser will be put there, since it does not throw on non-fatal errors. */ errorCollector: ErrorCollector; constructor(code: CodeFile, tokens: Token[], errorCollector: ErrorCollector); /** * Attempts to parse a file and return the AST with the ScadFile as a root node. * @throws ParsingError */ parse(): ScadFile; protected synchronize(e: ParsingError): void; /** * Parses a statement, including `use` and `include` when isAtRoot is set to true. * @param isAtRoot whther we are parsing a statement in the root of the file, set to false inside blocks or modules. */ protected statement(isAtRoot?: boolean): ErrorNode | AssignmentNode | UseStmt | IncludeStmt | ModuleInstantiationStmt | ModuleDeclarationStmt | FunctionDeclarationStmt | BlockStmt | NoopStmt | IfElseStatement; protected matchAssignmentOrModuleInstantation(): AssignmentNode | ModuleInstantiationStmt | IfElseStatement | null; protected blockStatement(): BlockStmt; protected moduleDeclarationStatement(): ModuleDeclarationStmt; protected functionDeclarationStatement(): FunctionDeclarationStmt; protected assignmentStatement(): AssignmentNode; protected moduleInstantiationStatement(): ModuleInstantiationStmt | IfElseStatement; protected ifElseStatement(): IfElseStatement; protected singleModuleInstantiation(): ModuleInstantiationStmt | IfElseStatement; /** * Parses an argument list including the finishing paren. Can handle trailing and extra commas as well as an empty arguments list. * The initial paren must be consumed. * @param allowPositional Set to true when in call mode, positional arguments will be allowed. */ protected args(allowPositional?: boolean, forceType?: AssignmentNodeRole | null): AssignmentNode[]; /** * Parses arguments from the 'for' loop comprehension. * The initial paren must be consumed. Stops on semicolon or right paren, but does not consume them. */ protected forComprehensionArgs(): AssignmentNode[]; /** * Consumes redundant commas and returns true if it consumed any. * * You can also pass an array of tokens to which all the comma tokens will be pushed. */ protected consumeUselessCommas(trailingArr?: Token[]): boolean; protected expression(): Expression; /** * Parses the ternary '? :' expression */ protected ternary(): Expression; /** * Parses the '||' operators */ protected logicalOr(): Expression; /** * Parses the '&&' operators */ protected logicalAnd(): Expression; /** * Parses the '==' and '!=' operators. */ protected equality(): Expression; protected comparsion(): Expression; protected addition(): Expression; protected multiplication(): Expression; /** * Parses b ^ e. */ protected exponentiation(): Expression; /** * Parses +expr, -expr and !expr. */ protected unary(): Expression; protected memberLookupOrArrayLookup(): Expression; protected finishCall(callee: Expression): Expression; protected primary(): Expression; /** * Handles the parsing of vector literals and range literals. */ protected bracketInsides(): Expression; protected anonymousFunction(): AnonymousFunctionExpr; protected listComprehensionElements(): Expression; protected listComprehensionFor(): Expression; protected listComprehensionElementsOrExpr(): Expression; protected consume(tt: TokenType, where: string): Token; protected matchToken(...toMatch: TokenType[]): boolean; protected checkToken(tt: TokenType): boolean; protected advance(): Token; protected isAtEnd(): boolean; protected peek(): Token; protected peekNext(): Token; protected getLocation(): CodeLocation; protected previous(): Token; }