antlr-ng
Version:
Next generation ANTLR Tool
57 lines (56 loc) • 2.36 kB
TypeScript
import { Tool } from "../Tool.js";
import { CommonTree } from "../tree/CommonTree.js";
import { Grammar } from "./Grammar.js";
import { GrammarAST } from "./ast/GrammarAST.js";
import { GrammarRootAST } from "./ast/GrammarRootAST.js";
/** Handle left-recursion and block-set transforms */
export declare class GrammarTransformPipeline {
private g;
private tool;
constructor(g: Grammar, tool: Tool);
/**
* Utility visitor that sets grammar ptr in each node
*
* @param g The grammar to set.
* @param tree The tree to visit.
*/
static setGrammarPtr(g: Grammar, tree: GrammarAST): void;
static augmentTokensWithOriginalPosition(g: Grammar, tree: GrammarAST): void;
process(): void;
reduceBlocksToSets(root: CommonTree): void;
/**
* Merges all the rules, token definitions, and named actions from imported grammars into the root grammar tree.
* Perform:
*
* (tokens { X (= Y 'y')) + (tokens { Z ) -> (tokens { X (= Y 'y') Z)
* (@ members {foo}) + (@ members {bar}) -> (@ members {foobar})
* (RULES (RULE x y)) + (RULES (RULE z)) -> (RULES (RULE x y z))
* Rules in root prevent same rule from being appended to RULES node.
*
* The goal is a complete combined grammar so we can ignore subordinate grammars.
*
* @param rootGrammar The root grammar to integrate the imported grammars into.
*/
integrateImportedGrammars(rootGrammar: Grammar): void;
/**
* Build lexer grammar from combined grammar that looks like:
*
* (COMBINED_GRAMMAR A
* (tokens { X (= Y 'y'))
* (OPTIONS (= x 'y'))
* (@ members {foo})
* (@ lexer header {package jj;})
* (RULES (RULE .+)))
*
* Move rules and actions to new tree, don't dup. Split AST apart. We'll have this grammar to share token symbols
* later. Don't generate tokenVocab or tokens{} section. Copy over named actions.
*
* Side-effects: it removes children from GRAMMAR & RULES nodes in combined AST. Anything cut out is dup'd before
* adding to lexer to avoid "who's ur daddy" issues.
*
* @param combinedGrammar The combined grammar to extract the implicit lexer from.
*
* @returns The lexer grammar AST.
*/
extractImplicitLexer(combinedGrammar: Grammar): GrammarRootAST | undefined;
}