UNPKG

antlr-ng

Version:

Next generation ANTLR Tool

38 lines (37 loc) 2.26 kB
import { Grammar } from "../tool/Grammar.js"; import { Rule } from "../tool/Rule.js"; import { GrammarAST } from "../tool/ast/GrammarAST.js"; import { SymbolCollector } from "./SymbolCollector.js"; /** * Do as much semantic checking as we can and fill in grammar with rules, actions, and token definitions. * The only side effects are in the grammar passed to process(). We consume a bunch of memory here while we build * up data structures to perform checking, but all of it goes away after this pipeline object gets garbage collected. * * After this pipeline finishes, we can be sure that the grammar is syntactically correct and that it's semantically * correct enough for us to attempt grammar analysis. We have assigned all token types. Note that imported grammars * bring in token and rule definitions but only the root grammar and any implicitly created lexer grammar * get their token definitions filled up. We are treating the imported grammars like includes. * * The semantic pipeline works on root grammars (those that do the importing, if any). Upon entry to the semantic * pipeline, all imported grammars should have been loaded into delegate grammar objects with their ASTs created. * The pipeline does the BasicSemanticChecks on the imported grammar before collecting symbols. We cannot perform the * simple checks such as undefined rule until we have collected all tokens and rules from the imported grammars into * a single collection. */ export declare class SemanticPipeline { private g; constructor(g: Grammar); process(): void; protected identifyStartRules(collector: SymbolCollector): void; protected assignLexerTokenTypes(g: Grammar, tokensDefs: GrammarAST[]): void; protected hasTypeOrMoreCommand(r: Rule): boolean; protected assignTokenTypes(g: Grammar, tokensDefs: GrammarAST[], tokenIDs: GrammarAST[], terminals: GrammarAST[]): void; /** * Assign constant values to custom channels defined in a grammar. * * @param g The grammar. * @param channelDefs A collection of AST nodes defining individual channels within a `channels{}` block * in the grammar. */ protected assignChannelTypes(g: Grammar, channelDefs: GrammarAST[]): void; }