Search in sources :

Example 11 with CommonTreeNodeStream

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);
}
Also used : BlockSetTransformer(org.antlr.v4.parse.BlockSetTransformer) GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 12 with CommonTreeNodeStream

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();
}
Also used : GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) CharStream(org.antlr.runtime.CharStream) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 13 with CommonTreeNodeStream

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);
}
Also used : GrammarAST(org.antlr.v4.tool.ast.GrammarAST) GrammarASTAdaptor(org.antlr.v4.parse.GrammarASTAdaptor) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Example 14 with CommonTreeNodeStream

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;
}
Also used : CommonTokenStream(org.antlr.runtime.CommonTokenStream) CommonTree(org.antlr.runtime.tree.CommonTree) CommonTreeNodeStream(org.antlr.runtime.tree.CommonTreeNodeStream)

Aggregations

CommonTreeNodeStream (org.antlr.runtime.tree.CommonTreeNodeStream)14 CommonTokenStream (org.antlr.runtime.CommonTokenStream)8 CommonTree (org.antlr.runtime.tree.CommonTree)8 GrammarASTAdaptor (org.antlr.v4.parse.GrammarASTAdaptor)5 FileInputStream (java.io.FileInputStream)3 InputStreamReader (java.io.InputStreamReader)3 ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)3 WindowingException (com.sap.hadoop.windowing.WindowingException)2 RecognitionException (org.antlr.runtime.RecognitionException)2 Token (org.antlr.runtime.Token)2 TokenSource (org.antlr.runtime.TokenSource)2 GrammarAST (org.antlr.v4.tool.ast.GrammarAST)2 LexerErrorInterface (org.jf.smali.LexerErrorInterface)2 org.jf.smali.smaliFlexLexer (org.jf.smali.smaliFlexLexer)2 org.jf.smali.smaliParser (org.jf.smali.smaliParser)2 org.jf.smali.smaliTreeWalker (org.jf.smali.smaliTreeWalker)2 SelectSpec (com.sap.hadoop.windowing.query2.specification.SelectSpec)1 SmaliDexException (com.wuntee.oter.exception.SmaliDexException)1 SmaliSyntaxException (com.wuntee.oter.exception.SmaliSyntaxException)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1