Search in sources :

Example 1 with ActionSplitter

use of org.antlr.v4.parse.ActionSplitter in project antlr4 by tunnelvisionlabs.

the class TestActionSplitter method getActionChunks.

public static List<String> getActionChunks(String a) {
    List<String> chunks = new ArrayList<String>();
    ActionSplitter splitter = new ActionSplitter(new ANTLRStringStream(a), new BlankActionSplitterListener());
    Token t = splitter.nextToken();
    while (t.getType() != Token.EOF) {
        chunks.add("'" + t.getText() + "'<" + t.getType() + ">");
        t = splitter.nextToken();
    }
    return chunks;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter) ArrayList(java.util.ArrayList) BlankActionSplitterListener(org.antlr.v4.semantics.BlankActionSplitterListener) Token(org.antlr.runtime.Token)

Example 2 with ActionSplitter

use of org.antlr.v4.parse.ActionSplitter in project antlr4 by tunnelvisionlabs.

the class ActionTranslator method translateActionChunk.

public static List<ActionChunk> translateActionChunk(OutputModelFactory factory, RuleFunction rf, String action, ActionAST node) {
    Token tokenWithinAction = node.token;
    ActionTranslator translator = new ActionTranslator(factory, node);
    translator.rf = rf;
    factory.getGrammar().tool.log("action-translator", "translate " + action);
    String altLabel = node.getAltLabel();
    if (rf != null) {
        translator.nodeContext = rf.ruleCtx;
        if (altLabel != null)
            translator.nodeContext = rf.altLabelCtxs.get(altLabel);
    }
    ANTLRStringStream in = new ANTLRStringStream(action);
    in.setLine(tokenWithinAction.getLine());
    in.setCharPositionInLine(tokenWithinAction.getCharPositionInLine());
    ActionSplitter trigger = new ActionSplitter(in, translator);
    // forces eval, triggers listener methods
    trigger.getActionTokens();
    return translator.chunks;
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter) Token(org.antlr.runtime.Token)

Example 3 with ActionSplitter

use of org.antlr.v4.parse.ActionSplitter in project antlr4 by tunnelvisionlabs.

the class ActionSniffer method examineAction.

public void examineAction() {
    // System.out.println("examine "+actionToken);
    ANTLRStringStream in = new ANTLRStringStream(actionToken.getText());
    in.setLine(actionToken.getLine());
    in.setCharPositionInLine(actionToken.getCharPositionInLine());
    ActionSplitter splitter = new ActionSplitter(in, this);
    // forces eval, triggers listener methods
    node.chunks = splitter.getActionTokens();
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter)

Example 4 with ActionSplitter

use of org.antlr.v4.parse.ActionSplitter in project antlr4 by tunnelvisionlabs.

the class AttributeChecks method examineAction.

public void examineAction() {
    // System.out.println("examine "+actionToken);
    ANTLRStringStream in = new ANTLRStringStream(actionToken.getText());
    in.setLine(actionToken.getLine());
    in.setCharPositionInLine(actionToken.getCharPositionInLine());
    ActionSplitter splitter = new ActionSplitter(in, this);
    // forces eval, triggers listener methods
    node.chunks = splitter.getActionTokens();
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter)

Example 5 with ActionSplitter

use of org.antlr.v4.parse.ActionSplitter in project antlr4 by tunnelvisionlabs.

the class UseDefAnalyzer method actionIsContextDependent.

public static boolean actionIsContextDependent(ActionAST actionAST) {
    ANTLRStringStream in = new ANTLRStringStream(actionAST.token.getText());
    in.setLine(actionAST.token.getLine());
    in.setCharPositionInLine(actionAST.token.getCharPositionInLine());
    // can't be simple bool with anon class
    final boolean[] dependent = new boolean[] { false };
    ActionSplitterListener listener = new BlankActionSplitterListener() {

        @Override
        public void nonLocalAttr(String expr, Token x, Token y) {
            dependent[0] = true;
        }

        @Override
        public void qualifiedAttr(String expr, Token x, Token y) {
            dependent[0] = true;
        }

        @Override
        public void setAttr(String expr, Token x, Token rhs) {
            dependent[0] = true;
        }

        @Override
        public void setExprAttribute(String expr) {
            dependent[0] = true;
        }

        @Override
        public void setNonLocalAttr(String expr, Token x, Token y, Token rhs) {
            dependent[0] = true;
        }

        @Override
        public void attr(String expr, Token x) {
            dependent[0] = true;
        }
    };
    ActionSplitter splitter = new ActionSplitter(in, listener);
    // forces eval, triggers listener methods
    splitter.getActionTokens();
    return dependent[0];
}
Also used : ANTLRStringStream(org.antlr.runtime.ANTLRStringStream) ActionSplitter(org.antlr.v4.parse.ActionSplitter) ActionSplitterListener(org.antlr.v4.parse.ActionSplitterListener) Token(org.antlr.runtime.Token)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)12 ActionSplitter (org.antlr.v4.parse.ActionSplitter)12 Token (org.antlr.runtime.Token)6 ArrayList (java.util.ArrayList)2 ActionSplitterListener (org.antlr.v4.parse.ActionSplitterListener)2 BlankActionSplitterListener (org.antlr.v4.semantics.BlankActionSplitterListener)2