Search in sources :

Example 1 with ArgRef

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

the class ActionTranslator method qualifiedAttr.

@Override
public void qualifiedAttr(String expr, Token x, Token y) {
    gen.g.tool.log("action-translator", "qattr " + x + "." + y);
    if (node.resolver.resolveToAttribute(x.getText(), node) != null) {
        // must be a member access to a predefined attribute like $ctx.foo
        attr(expr, x);
        chunks.add(new ActionText(nodeContext, "." + y.getText()));
        return;
    }
    Attribute a = node.resolver.resolveToAttribute(x.getText(), y.getText(), node);
    if (a == null) {
        // Added in response to https://github.com/antlr/antlr4/issues/1211
        gen.g.tool.errMgr.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE, gen.g.fileName, x, x.getText(), "rule");
        return;
    }
    switch(a.dict.type) {
        // has to be current rule
        case ARG:
            chunks.add(new ArgRef(nodeContext, y.getText()));
            break;
        case RET:
            chunks.add(new QRetValueRef(nodeContext, getRuleLabel(x.getText()), y.getText()));
            break;
        case PREDEFINED_RULE:
            chunks.add(getRulePropertyRef(x, y));
            break;
        case TOKEN:
            chunks.add(getTokenPropertyRef(x, y));
            break;
    }
}
Also used : ActionText(org.antlr.v4.codegen.model.chunk.ActionText) Attribute(org.antlr.v4.tool.Attribute) ArgRef(org.antlr.v4.codegen.model.chunk.ArgRef) QRetValueRef(org.antlr.v4.codegen.model.chunk.QRetValueRef)

Example 2 with ArgRef

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

the class ActionTranslator method attr.

@Override
public void attr(String expr, Token x) {
    gen.g.tool.log("action-translator", "attr " + x);
    Attribute a = node.resolver.resolveToAttribute(x.getText(), node);
    if (a != null) {
        switch(a.dict.type) {
            case ARG:
                chunks.add(new ArgRef(nodeContext, x.getText()));
                break;
            case RET:
                chunks.add(new RetValueRef(rf.ruleCtx, x.getText()));
                break;
            case LOCAL:
                chunks.add(new LocalRef(nodeContext, x.getText()));
                break;
            case PREDEFINED_RULE:
                chunks.add(getRulePropertyRef(x));
                break;
        }
    }
    if (node.resolver.resolvesToToken(x.getText(), node)) {
        // $label
        chunks.add(new TokenRef(nodeContext, getTokenLabel(x.getText())));
        return;
    }
    if (node.resolver.resolvesToLabel(x.getText(), node)) {
        // $x for x=ID etc...
        chunks.add(new LabelRef(nodeContext, getTokenLabel(x.getText())));
        return;
    }
    if (node.resolver.resolvesToListLabel(x.getText(), node)) {
        // $ids for ids+=ID etc...
        chunks.add(new ListLabelRef(nodeContext, x.getText()));
        return;
    }
    Rule r = factory.getGrammar().getRule(x.getText());
    if (r != null) {
        // $r for r rule ref
        chunks.add(new LabelRef(nodeContext, getRuleLabel(x.getText())));
    }
}
Also used : ListLabelRef(org.antlr.v4.codegen.model.chunk.ListLabelRef) Attribute(org.antlr.v4.tool.Attribute) TokenRef(org.antlr.v4.codegen.model.chunk.TokenRef) QRetValueRef(org.antlr.v4.codegen.model.chunk.QRetValueRef) RetValueRef(org.antlr.v4.codegen.model.chunk.RetValueRef) Rule(org.antlr.v4.tool.Rule) ArgRef(org.antlr.v4.codegen.model.chunk.ArgRef) LabelRef(org.antlr.v4.codegen.model.chunk.LabelRef) ListLabelRef(org.antlr.v4.codegen.model.chunk.ListLabelRef) LocalRef(org.antlr.v4.codegen.model.chunk.LocalRef)

Example 3 with ArgRef

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

the class ActionTranslator method attr.

@Override
public void attr(String expr, Token x) {
    gen.g.tool.log("action-translator", "attr " + x);
    Attribute a = node.resolver.resolveToAttribute(x.getText(), node);
    if (a != null) {
        switch(a.dict.type) {
            case ARG:
                chunks.add(new ArgRef(nodeContext, x.getText()));
                break;
            case RET:
                chunks.add(new RetValueRef(rf.ruleCtx, x.getText()));
                break;
            case LOCAL:
                chunks.add(new LocalRef(nodeContext, x.getText()));
                break;
            case PREDEFINED_RULE:
                chunks.add(getRulePropertyRef(x));
                break;
        }
    }
    if (node.resolver.resolvesToToken(x.getText(), node)) {
        // $label
        chunks.add(new TokenRef(nodeContext, getTokenLabel(x.getText())));
        return;
    }
    if (node.resolver.resolvesToLabel(x.getText(), node)) {
        // $x for x=ID etc...
        chunks.add(new LabelRef(nodeContext, getTokenLabel(x.getText())));
        return;
    }
    if (node.resolver.resolvesToListLabel(x.getText(), node)) {
        // $ids for ids+=ID etc...
        chunks.add(new ListLabelRef(nodeContext, x.getText()));
        return;
    }
    Rule r = factory.getGrammar().getRule(x.getText());
    if (r != null) {
        // $r for r rule ref
        chunks.add(new LabelRef(nodeContext, getRuleLabel(x.getText())));
    }
}
Also used : ListLabelRef(org.antlr.v4.codegen.model.chunk.ListLabelRef) Attribute(org.antlr.v4.tool.Attribute) TokenRef(org.antlr.v4.codegen.model.chunk.TokenRef) QRetValueRef(org.antlr.v4.codegen.model.chunk.QRetValueRef) RetValueRef(org.antlr.v4.codegen.model.chunk.RetValueRef) Rule(org.antlr.v4.tool.Rule) ArgRef(org.antlr.v4.codegen.model.chunk.ArgRef) LabelRef(org.antlr.v4.codegen.model.chunk.LabelRef) ListLabelRef(org.antlr.v4.codegen.model.chunk.ListLabelRef) LocalRef(org.antlr.v4.codegen.model.chunk.LocalRef)

Example 4 with ArgRef

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

the class ActionTranslator method qualifiedAttr.

@Override
public void qualifiedAttr(String expr, Token x, Token y) {
    gen.g.tool.log("action-translator", "qattr " + x + "." + y);
    if (node.resolver.resolveToAttribute(x.getText(), node) != null) {
        // must be a member access to a predefined attribute like $ctx.foo
        attr(expr, x);
        chunks.add(new ActionText(nodeContext, "." + y.getText()));
        return;
    }
    Attribute a = node.resolver.resolveToAttribute(x.getText(), y.getText(), node);
    if (a == null) {
        // Added in response to https://github.com/antlr/antlr4/issues/1211
        gen.g.tool.errMgr.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE, gen.g.fileName, x, x.getText(), "rule");
        return;
    }
    switch(a.dict.type) {
        // has to be current rule
        case ARG:
            chunks.add(new ArgRef(nodeContext, y.getText()));
            break;
        case RET:
            chunks.add(new QRetValueRef(nodeContext, getRuleLabel(x.getText()), y.getText()));
            break;
        case PREDEFINED_RULE:
            chunks.add(getRulePropertyRef(x, y));
            break;
        case TOKEN:
            chunks.add(getTokenPropertyRef(x, y));
            break;
    }
}
Also used : ActionText(org.antlr.v4.codegen.model.chunk.ActionText) Attribute(org.antlr.v4.tool.Attribute) ArgRef(org.antlr.v4.codegen.model.chunk.ArgRef) QRetValueRef(org.antlr.v4.codegen.model.chunk.QRetValueRef)

Aggregations

ArgRef (org.antlr.v4.codegen.model.chunk.ArgRef)4 QRetValueRef (org.antlr.v4.codegen.model.chunk.QRetValueRef)4 Attribute (org.antlr.v4.tool.Attribute)4 ActionText (org.antlr.v4.codegen.model.chunk.ActionText)2 LabelRef (org.antlr.v4.codegen.model.chunk.LabelRef)2 ListLabelRef (org.antlr.v4.codegen.model.chunk.ListLabelRef)2 LocalRef (org.antlr.v4.codegen.model.chunk.LocalRef)2 RetValueRef (org.antlr.v4.codegen.model.chunk.RetValueRef)2 TokenRef (org.antlr.v4.codegen.model.chunk.TokenRef)2 Rule (org.antlr.v4.tool.Rule)2