use of org.antlr.runtime.tree.CommonTreeNodeStream in project antlr4 by antlr.
the class GrammarTransformPipeline method reduceBlocksToSets.
public void reduceBlocksToSets(GrammarAST root) {
CommonTreeNodeStream nodes = new CommonTreeNodeStream(new GrammarASTAdaptor(), root);
GrammarASTAdaptor adaptor = new GrammarASTAdaptor();
BlockSetTransformer transformer = new BlockSetTransformer(nodes, g);
transformer.setTreeAdaptor(adaptor);
transformer.downup(root);
}
use of org.antlr.runtime.tree.CommonTreeNodeStream in project antlr4 by antlr.
the class GrammarAST method toTokenString.
public String toTokenString() {
CharStream input = this.token.getInputStream();
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(input);
CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor, this);
StringBuilder buf = new StringBuilder();
GrammarAST o = (GrammarAST) nodes.LT(1);
int type = adaptor.getType(o);
while (type != Token.EOF) {
buf.append(" ");
buf.append(o.getText());
nodes.consume();
o = (GrammarAST) nodes.LT(1);
type = adaptor.getType(o);
}
return buf.toString();
}
use of org.antlr.runtime.tree.CommonTreeNodeStream in project antlr4 by antlr.
the class OutputModelController method buildNormalRuleFunction.
public void buildNormalRuleFunction(Rule r, RuleFunction function) {
CodeGenerator gen = delegate.getGenerator();
// TRIGGER factory functions for rule alts, elements
GrammarASTAdaptor adaptor = new GrammarASTAdaptor(r.ast.token.getInputStream());
GrammarAST blk = (GrammarAST) r.ast.getFirstChildWithType(ANTLRParser.BLOCK);
CommonTreeNodeStream nodes = new CommonTreeNodeStream(adaptor, blk);
walker = new SourceGenTriggers(nodes, this);
try {
// walk AST of rule alts/elements
function.code = DefaultOutputModelFactory.list(walker.block(null, null));
function.hasLookaheadBlock = walker.hasLookaheadBlock;
} catch (org.antlr.runtime.RecognitionException e) {
e.printStackTrace(System.err);
}
function.ctxType = gen.getTarget().getRuleFunctionContextStructName(function);
function.postamble = rulePostamble(function, r);
}
use of org.antlr.runtime.tree.CommonTreeNodeStream in project drools by kiegroup.
the class DSLTokenizedMappingFile method buildFileMappingWalker.
private DSLMapWalker buildFileMappingWalker(final List<ParserError> errors, CharStream stream) throws RecognitionException {
DSLMapLexer lexer = new DSLMapLexer(stream);
CommonTokenStream tokens = new CommonTokenStream();
tokens.setTokenSource(lexer);
DSLMapParser parser = new DSLMapParser(tokens);
DSLMapParser.mapping_file_return example = parser.mapping_file();
CommonTree tree = (CommonTree) example.getTree();
// logger.info(tree.toStringTree());
CommonTreeNodeStream nodes = new CommonTreeNodeStream(tree);
DSLMapWalker walker = new DSLMapWalker(nodes);
errors.addAll(lexer.getErrors());
errors.addAll(parser.getErrors());
return walker;
}
Aggregations