univac
Version:
Generate AST of lots of common programming languages using antlr4. JavaScript API and CLI tool.
40 lines (39 loc) • 1.47 kB
TypeScript
import { Lexer, Parser } from 'antlr4';
import { Language, Node } from './types';
export interface ParserImpl {
/**
* For antlr4 grammars.
*/
Lexer?: typeof Lexer;
/**
* For antlr4 grammars.
*/
Parser?: typeof Parser;
/**
* For antlr4 grammars. Some implementations require two-steps, like R or ObjectiveC. The later has a
* preprocessor that removes directives / spaces for its output to be compiled by the real parser.
*/
Filter?: typeof Parser;
/**
* For antlr4 grammars.
*/
mainRule?: string;
/**
* For antlr4 grammars. A node predicate. If true and it will be remoed if:
*
* * has 0 children
* * has 1 child an dit child or its parent also have 1 child.X
*/
redundantTypes?(node: Node, parent?: Node): boolean;
/**
* Mostly for antlr4 grammars, gives the possibility to an implementation to completly mutate the AST at
* piaccere, for example, renaming original, types, removing nodes with custom policies, etc.
*/
mutate?(ast: Node, impl: ParserImpl): Node;
/**
* For tree-sitter AST parsers. path to the parser implementation .wasm file.
*/
treeSitterParser?: string;
}
export declare function getParserImpl(language: Language): Promise<ParserImpl>;
export declare function preventRedundantTypeNames(node: Node, parent: Node | undefined, predicate: (node: Node, parent: Node | undefined) => boolean): boolean;