@maniascript/parser
Version:
Maniascript parser
60 lines (59 loc) • 1.97 kB
TypeScript
import { CommonTokenStream, CharStream, Lexer, Parser } from 'antlr4ng';
import { ManiaScriptLexer } from '../antlr/ManiaScriptLexer.js';
import { ManiaScriptParser, ProgramContext } from '../antlr/ManiaScriptParser.js';
import { type AST } from './ast.js';
import { ScopeManager } from './scope.js';
import { SourceLocationRange } from './position.js';
import { SymbolTable } from './symbol-table.js';
interface ParseError {
source: SourceLocationRange;
message: string;
}
interface ParseResult {
success: boolean;
errors: ParseError[];
tree: ProgramContext;
ast: AST;
scopeManager: ScopeManager;
symbolTable: SymbolTable | null;
chars: CharStream;
lexer: Lexer;
tokens: CommonTokenStream;
parser: Parser;
profiling: ProfileInfo[];
}
interface ParseOptions {
CustomLexer?: typeof ManiaScriptLexer;
CustomParser?: typeof ManiaScriptParser;
twoStepsParsing?: boolean;
profile?: boolean;
msApiPath?: string;
lexerClasses?: Set<string>;
lexerGame?: string;
buildAst?: boolean;
buildScopes?: boolean;
buildSymbolTable?: boolean;
}
interface ProfileInfo {
rule: string;
time: number;
invocations: number;
'lookahead total (SLL)': number;
'lookahead min (SLL)': number;
'lookahead max (SLL)': number;
'ATN transition (SLL)': number;
'DFA transition (SLL)': number;
'LL fallback': number;
'lookahead total (LL)': number;
'lookahead min (LL)': number;
'lookahead max (LL)': number;
'ATN transition (LL)': number;
'DFA transition (LL)': number;
ambiguities: number;
predicates: number;
context: number;
errors: number;
}
declare function parse(input: string, { CustomLexer, CustomParser, twoStepsParsing, profile, msApiPath, lexerClasses, lexerGame, buildAst, buildScopes, buildSymbolTable }?: ParseOptions): Promise<ParseResult>;
export { parse };
export type { ParseError, ParseResult, ParseOptions, ProfileInfo };