Search in sources :

Example 1 with SetAttr

use of org.antlr.v4.codegen.model.chunk.SetAttr in project antlr4 by antlr.

the class AttributeChecks method setAttr.

@Override
public void setAttr(String expr, Token x, Token rhs) {
    if (g.isLexer()) {
        errMgr.grammarError(ErrorType.ATTRIBUTE_IN_LEXER_ACTION, g.fileName, x, x.getText(), expr);
        return;
    }
    if (node.resolver.resolveToAttribute(x.getText(), node) == null) {
        ErrorType errorType = ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE;
        if (node.resolver.resolvesToListLabel(x.getText(), node)) {
            // $ids for ids+=ID etc...
            errorType = ErrorType.ASSIGNMENT_TO_LIST_LABEL;
        }
        errMgr.grammarError(errorType, g.fileName, x, x.getText(), expr);
    }
    new AttributeChecks(g, r, alt, node, rhs).examineAction();
}
Also used : ErrorType(org.antlr.v4.tool.ErrorType)

Example 2 with SetAttr

use of org.antlr.v4.codegen.model.chunk.SetAttr in project antlr4 by antlr.

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)

Example 3 with SetAttr

use of org.antlr.v4.codegen.model.chunk.SetAttr in project antlr4 by antlr.

the class ActionTranslator method setAttr.

@Override
public void setAttr(String expr, Token x, Token rhs) {
    gen.g.tool.log("action-translator", "setAttr " + x + " " + rhs);
    List<ActionChunk> rhsChunks = translateActionChunk(factory, rf, rhs.getText(), node);
    SetAttr s = new SetAttr(nodeContext, x.getText(), rhsChunks);
    chunks.add(s);
}
Also used : SetAttr(org.antlr.v4.codegen.model.chunk.SetAttr) ActionChunk(org.antlr.v4.codegen.model.chunk.ActionChunk)

Aggregations

ANTLRStringStream (org.antlr.runtime.ANTLRStringStream)1 Token (org.antlr.runtime.Token)1 ActionChunk (org.antlr.v4.codegen.model.chunk.ActionChunk)1 SetAttr (org.antlr.v4.codegen.model.chunk.SetAttr)1 ActionSplitter (org.antlr.v4.parse.ActionSplitter)1 ActionSplitterListener (org.antlr.v4.parse.ActionSplitterListener)1 ErrorType (org.antlr.v4.tool.ErrorType)1