Search in sources :

Example 1 with Condition

use of org.eclipse.xtext.Condition in project xtext-eclipse by eclipse.

the class AbstractAntlrGrammarWithActionsGenerator method _ebnf2.

@Override
protected String _ebnf2(final Group it, final AntlrOptions options, final boolean supportActions) {
    String _xifexpression = null;
    Condition _guardCondition = it.getGuardCondition();
    boolean _tripleEquals = (_guardCondition == null);
    if (_tripleEquals) {
        _xifexpression = super._ebnf2(it, options, supportActions);
    } else {
        String _guardConditionToAntlr = AntlrGrammarGenUtil.guardConditionToAntlr(it);
        String _plus = (_guardConditionToAntlr + "(");
        String __ebnf2 = super._ebnf2(it, options, supportActions);
        String _plus_1 = (_plus + __ebnf2);
        _xifexpression = (_plus_1 + ")");
    }
    return _xifexpression;
}
Also used : Condition(org.eclipse.xtext.Condition)

Example 2 with Condition

use of org.eclipse.xtext.Condition in project xtext-eclipse by eclipse.

the class AbstractAntlrGrammarWithActionsGenerator method _dataTypeEbnf2.

@Override
protected String _dataTypeEbnf2(final Group it, final boolean supportActions) {
    String _xifexpression = null;
    Condition _guardCondition = it.getGuardCondition();
    boolean _tripleEquals = (_guardCondition == null);
    if (_tripleEquals) {
        _xifexpression = super._dataTypeEbnf2(it, supportActions);
    } else {
        String _guardConditionToAntlr = AntlrGrammarGenUtil.guardConditionToAntlr(it);
        String _plus = (_guardConditionToAntlr + "(");
        String __dataTypeEbnf2 = super._dataTypeEbnf2(it, supportActions);
        String _plus_1 = (_plus + __dataTypeEbnf2);
        _xifexpression = (_plus_1 + ")");
    }
    return _xifexpression;
}
Also used : Condition(org.eclipse.xtext.Condition)

Example 3 with Condition

use of org.eclipse.xtext.Condition in project xtext-core by eclipse.

the class XtextLinkerTest method testGuardLinking.

@Test
public void testGuardLinking() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate test \'http://test\'");
    _builder.newLine();
    _builder.append("Root<MyArg>: <MyArg> name=ID | <!MyArg> name=STRING;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    EObject _model = this.getModel(grammarAsString);
    final Grammar grammar = ((Grammar) _model);
    AbstractRule _head = IterableExtensions.<AbstractRule>head(grammar.getRules());
    final ParserRule rootRule = ((ParserRule) _head);
    AbstractElement _alternatives = rootRule.getAlternatives();
    final Alternatives alternatives = ((Alternatives) _alternatives);
    AbstractElement _head_1 = IterableExtensions.<AbstractElement>head(alternatives.getElements());
    Condition _guardCondition = ((Group) _head_1).getGuardCondition();
    final ParameterReference firstGuard = ((ParameterReference) _guardCondition);
    Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), firstGuard.getParameter());
    AbstractElement _last = IterableExtensions.<AbstractElement>last(alternatives.getElements());
    Condition _guardCondition_1 = ((Group) _last).getGuardCondition();
    final Negation secondGuard = ((Negation) _guardCondition_1);
    Condition _value = secondGuard.getValue();
    Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), ((ParameterReference) _value).getParameter());
}
Also used : LiteralCondition(org.eclipse.xtext.LiteralCondition) Condition(org.eclipse.xtext.Condition) ParserRule(org.eclipse.xtext.ParserRule) Group(org.eclipse.xtext.Group) AbstractElement(org.eclipse.xtext.AbstractElement) Negation(org.eclipse.xtext.Negation) ParameterReference(org.eclipse.xtext.ParameterReference) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) AbstractRule(org.eclipse.xtext.AbstractRule) Alternatives(org.eclipse.xtext.Alternatives) Test(org.junit.Test)

Example 4 with Condition

use of org.eclipse.xtext.Condition in project xtext-core by eclipse.

the class XtextLinkerTest method testNamedParameterLinking.

@Test
public void testNamedParameterLinking() throws Exception {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("grammar test.Lang with org.eclipse.xtext.common.Terminals");
    _builder.newLine();
    _builder.append("generate test \'http://test\'");
    _builder.newLine();
    _builder.append("Root<MyArg>: rule=Rule<MyArg>;");
    _builder.newLine();
    _builder.append("Rule<MyParam>: name=ID child=Root<MyArg=MyParam>?;");
    _builder.newLine();
    final String grammarAsString = _builder.toString();
    EObject _model = this.getModel(grammarAsString);
    final Grammar grammar = ((Grammar) _model);
    AbstractRule _head = IterableExtensions.<AbstractRule>head(grammar.getRules());
    final ParserRule rootRule = ((ParserRule) _head);
    AbstractRule _last = IterableExtensions.<AbstractRule>last(grammar.getRules());
    final ParserRule lastRule = ((ParserRule) _last);
    AbstractElement _alternatives = lastRule.getAlternatives();
    AbstractElement _last_1 = IterableExtensions.<AbstractElement>last(((Group) _alternatives).getElements());
    final Assignment lastAssignment = ((Assignment) _last_1);
    AbstractElement _terminal = lastAssignment.getTerminal();
    final RuleCall ruleCall = ((RuleCall) _terminal);
    final NamedArgument argument = IterableExtensions.<NamedArgument>head(ruleCall.getArguments());
    Assert.assertEquals(IterableExtensions.<Parameter>head(rootRule.getParameters()), argument.getParameter());
    Condition _value = argument.getValue();
    Assert.assertEquals(IterableExtensions.<Parameter>head(lastRule.getParameters()), ((ParameterReference) _value).getParameter());
}
Also used : Assignment(org.eclipse.xtext.Assignment) LiteralCondition(org.eclipse.xtext.LiteralCondition) Condition(org.eclipse.xtext.Condition) ParserRule(org.eclipse.xtext.ParserRule) AbstractElement(org.eclipse.xtext.AbstractElement) EObject(org.eclipse.emf.ecore.EObject) InternalEObject(org.eclipse.emf.ecore.InternalEObject) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Grammar(org.eclipse.xtext.Grammar) NamedArgument(org.eclipse.xtext.NamedArgument) AbstractRule(org.eclipse.xtext.AbstractRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 5 with Condition

use of org.eclipse.xtext.Condition in project xtext-core by eclipse.

the class AbstractAntlrGrammarWithActionsGenerator method _ebnf2.

@Override
protected String _ebnf2(final Group it, final AntlrOptions options, final boolean supportActions) {
    String _xifexpression = null;
    Condition _guardCondition = it.getGuardCondition();
    boolean _tripleEquals = (_guardCondition == null);
    if (_tripleEquals) {
        _xifexpression = super._ebnf2(it, options, supportActions);
    } else {
        String _guardConditionToAntlr = AntlrGrammarGenUtil.guardConditionToAntlr(it);
        String _plus = (_guardConditionToAntlr + "(");
        String __ebnf2 = super._ebnf2(it, options, supportActions);
        String _plus_1 = (_plus + __ebnf2);
        _xifexpression = (_plus_1 + ")");
    }
    return _xifexpression;
}
Also used : Condition(org.eclipse.xtext.Condition)

Aggregations

Condition (org.eclipse.xtext.Condition)15 EObject (org.eclipse.emf.ecore.EObject)6 AbstractElement (org.eclipse.xtext.AbstractElement)6 AbstractRule (org.eclipse.xtext.AbstractRule)6 ParserRule (org.eclipse.xtext.ParserRule)6 InternalEObject (org.eclipse.emf.ecore.InternalEObject)5 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5 Grammar (org.eclipse.xtext.Grammar)5 LiteralCondition (org.eclipse.xtext.LiteralCondition)5 NamedArgument (org.eclipse.xtext.NamedArgument)5 RuleCall (org.eclipse.xtext.RuleCall)5 Test (org.junit.Test)5 Assignment (org.eclipse.xtext.Assignment)4 CompositeCondition (org.eclipse.xtext.CompositeCondition)2 Group (org.eclipse.xtext.Group)2 ImmutableSet (com.google.common.collect.ImmutableSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Set (java.util.Set)1