Search code examples
eclipsedslxtextemfecore

Avoid Xtext multiple alternatives warnings


in my xtext dsl i have defined the following rules:

Port returns tdg::Port:
    'port'
    'kind' kind=Kind
    'type' type=Type;

enum Kind returns tdg::PortKind:
    In='in' | Out='out';

enum Type returns tdg::PortType:
    Numeric | String | Boolean | Tuple;

The tdg classes come frome an ecore model. I get the following warnings when i compile the dsl grammar. How can i avoid them?

warning(200): ../com.isax.testdatagen.dsl/src-gen/com/isax/testdatagen/parser/antlr/internal/InternalTdgDSL.g:250:1: Decision can match input such as "'port' 'kind' 'in' 'type' 'String'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ../com.isax.testdatagen.dsl/src-gen/com/isax/testdatagen/parser/antlr/internal/InternalTdgDSL.g:250:1: Decision can match input such as "'port' 'kind' 'in' 'type' 'Boolean'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ../com.isax.testdatagen.dsl/src-gen/com/isax/testdatagen/parser/antlr/internal/InternalTdgDSL.g:250:1: Decision can match input such as "'port' 'kind' 'in' 'type' 'Tuple'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ../com.isax.testdatagen.dsl/src-gen/com/isax/testdatagen/parser/antlr/internal/InternalTdgDSL.g:250:1: Decision can match input such as "'port' 'kind' 'in' 'type' 'Numeric'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ../com.isax.testdatagen.dsl.ui/src-gen/com/isax/testdatagen/ui/contentassist/antlr/internal/InternalTdgDSL.g:854:30: Decision can match input such as "'port' 'kind' 'in' 'type' 'Numeric'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ../com.isax.testdatagen.dsl.ui/src-gen/com/isax/testdatagen/ui/contentassist/antlr/internal/InternalTdgDSL.g:854:30: Decision can match input such as "'port' 'kind' 'in' 'type' 'String'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ../com.isax.testdatagen.dsl.ui/src-gen/com/isax/testdatagen/ui/contentassist/antlr/internal/InternalTdgDSL.g:854:30: Decision can match input such as "'port' 'kind' 'in' 'type' 'Boolean'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input warning(200): ../com.isax.testdatagen.dsl.ui/src-gen/com/isax/testdatagen/ui/contentassist/antlr/internal/InternalTdgDSL.g:854:30: Decision can match input such as "'port' 'kind' 'in' 'type' 'Tuple'" using multiple alternatives: 1, 2 As a result, alternative(s) 2 were disabled for that input


Solution

  • This kind of "multiple alternatives" warning may be caused by a rule that is reachable using two "paths" of alternatives, e.g.

    Model:
        Rule1a | Rule1b;
    
    Rule1a:
        Rule2 | Rule1b;
    
    Rule1b:
        {Rule1b} 'rule1b';
    
    Rule2: 
        {Rule2} 'rule2';
    

    Here, rule1b is reachable from the rule "Model" using two paths: Directly from "Model" and indirectly through "Rule1a".

    As Christian stated, your error message cannot possibly be caused by the rules you listed. If your grammar contains only Model: ports+=Port*; apart from these, maybe you are generating a different grammar than you think you are?

    In any case, to find the cause of the problem, you have to identify the rule which has ambiguous instances: Open com.isax.testdatagen.dsl/src-gen/com/isax/testdatagen/parser/antlr/internal/InternalTdgDSL.g line 250 (as printed in the log) and find out which rule it belongs to. In my example, the error lies in the Antlr rule ruleModel, which corresponds to the Xtext rule Model.