Search in sources :

Example 26 with UnorderedGroup

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

the class AntlrContentAssistGrammarGenerator method ruleImpl.

protected CharSequence ruleImpl(final UnorderedGroup it, final Grammar grammar, final AntlrOptions options) {
    StringConcatenation _builder = new StringConcatenation();
    String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
    _builder.append(_contentAssistRuleName);
    _builder.append("__");
    String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
    _builder.append(_gaElementIdentifier);
    _builder.append("__Impl");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("@init {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int stackSize = keepStackSize();");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("boolean selected = false;");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append(":");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("(");
    _builder.newLine();
    {
        Iterable<Pair<Integer, AbstractElement>> _indexed = IterableExtensions.<AbstractElement>indexed(it.getElements());
        boolean _hasElements = false;
        for (final Pair<Integer, AbstractElement> element : _indexed) {
            if (!_hasElements) {
                _hasElements = true;
            } else {
                _builder.appendImmediate("|", "\t\t");
            }
            _builder.append("\t\t");
            _builder.append("( ");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append("{getUnorderedGroupHelper().canSelect(grammarAccess.");
            String _gaRuleElementAccessor = this._grammarAccessExtensions.gaRuleElementAccessor(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
            _builder.append(_gaRuleElementAccessor, "\t\t\t");
            _builder.append(", ");
            Integer _key = element.getKey();
            _builder.append(_key, "\t\t\t");
            _builder.append(")}?=>(");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t\t");
            _builder.append("getUnorderedGroupHelper().select(grammarAccess.");
            String _gaRuleElementAccessor_1 = this._grammarAccessExtensions.gaRuleElementAccessor(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
            _builder.append(_gaRuleElementAccessor_1, "\t\t\t\t\t");
            _builder.append(", ");
            Integer _key_1 = element.getKey();
            _builder.append(_key_1, "\t\t\t\t\t");
            _builder.append(");");
            _builder.newLineIfNotEmpty();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("{");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t\t");
            _builder.append("selected = true;");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("}");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append("(");
            _builder.newLine();
            {
                boolean _isMultipleCardinality = GrammarUtil.isMultipleCardinality(element.getValue());
                if (_isMultipleCardinality) {
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("(");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ before(grammarAccess.");
                    String _grammarElementAccess = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("(");
                    String _ebnf2 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2, "\t\t\t\t\t\t");
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ after(grammarAccess.");
                    String _grammarElementAccess_1 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_1, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append(")");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("(");
                    _builder.newLine();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ before(grammarAccess.");
                    String _grammarElementAccess_2 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_2, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("((");
                    String _ebnf2_1 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2_1, "\t\t\t\t\t\t");
                    _builder.append(")=>");
                    String _ebnf2_2 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2_2, "\t\t\t\t\t\t");
                    _builder.append(")*");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("\t");
                    _builder.append("{ after(grammarAccess.");
                    String _grammarElementAccess_3 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_3, "\t\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append(")");
                    _builder.newLine();
                } else {
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("{ before(grammarAccess.");
                    String _grammarElementAccess_4 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_4, "\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("(");
                    String _ebnf2_3 = this.ebnf2(element.getValue(), options, false);
                    _builder.append(_ebnf2_3, "\t\t\t\t\t");
                    _builder.append(")");
                    _builder.newLineIfNotEmpty();
                    _builder.append("\t\t");
                    _builder.append("\t\t\t");
                    _builder.append("{ after(grammarAccess.");
                    String _grammarElementAccess_5 = this._grammarAccessExtensions.grammarElementAccess(AntlrGrammarGenUtil.<AbstractElement>getOriginalElement(element.getValue()));
                    _builder.append(_grammarElementAccess_5, "\t\t\t\t\t");
                    _builder.append("); }");
                    _builder.newLineIfNotEmpty();
                }
            }
            _builder.append("\t\t");
            _builder.append("\t\t");
            _builder.append(")");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append("\t");
            _builder.append(")");
            _builder.newLine();
            _builder.append("\t\t");
            _builder.append(")");
            _builder.newLine();
        }
    }
    _builder.append("\t\t");
    _builder.append(")");
    _builder.newLine();
    _builder.append(";");
    _builder.newLine();
    _builder.append("finally {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("if (selected)");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("getUnorderedGroupHelper().returnFromSelection(grammarAccess.");
    String _gaRuleElementAccessor_2 = this._grammarAccessExtensions.gaRuleElementAccessor(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
    _builder.append(_gaRuleElementAccessor_2, "\t\t");
    _builder.append(");");
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("restoreStackSize(stackSize);");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    return _builder;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) UnorderedGroup(org.eclipse.xtext.UnorderedGroup) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) Pair(org.eclipse.xtext.xbase.lib.Pair)

Example 27 with UnorderedGroup

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

the class AntlrContentAssistGrammarGenerator method ruleImpl.

protected CharSequence ruleImpl(final UnorderedGroup it, final Grammar grammar, final AntlrOptions options, final int index) {
    StringConcatenation _builder = new StringConcatenation();
    String _contentAssistRuleName = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
    _builder.append(_contentAssistRuleName);
    _builder.append("__");
    String _gaElementIdentifier = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
    _builder.append(_gaElementIdentifier);
    _builder.append("__");
    _builder.append(index);
    _builder.newLineIfNotEmpty();
    _builder.append("\t");
    _builder.append("@init {");
    _builder.newLine();
    _builder.append("\t\t");
    _builder.append("int stackSize = keepStackSize();");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("}");
    _builder.newLine();
    _builder.append(":");
    _builder.newLine();
    _builder.append("\t");
    String _contentAssistRuleName_1 = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
    _builder.append(_contentAssistRuleName_1, "\t");
    _builder.append("__");
    String _gaElementIdentifier_1 = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
    _builder.append(_gaElementIdentifier_1, "\t");
    _builder.append("__Impl");
    _builder.newLineIfNotEmpty();
    {
        int _size = it.getElements().size();
        boolean _greaterThan = (_size > (index + 1));
        if (_greaterThan) {
            _builder.append("\t");
            String _contentAssistRuleName_2 = AntlrGrammarGenUtil.getContentAssistRuleName(GrammarUtil.containingRule(it));
            _builder.append(_contentAssistRuleName_2, "\t");
            _builder.append("__");
            String _gaElementIdentifier_2 = this._grammarAccessExtensions.gaElementIdentifier(AntlrGrammarGenUtil.<UnorderedGroup>getOriginalElement(it));
            _builder.append(_gaElementIdentifier_2, "\t");
            _builder.append("__");
            _builder.append((index + 1), "\t");
            _builder.append("?");
            _builder.newLineIfNotEmpty();
        }
    }
    _builder.append(";");
    _builder.newLine();
    _builder.append("finally {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("restoreStackSize(stackSize);");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    _builder.newLine();
    {
        int _size_1 = it.getElements().size();
        boolean _greaterThan_1 = (_size_1 > (index + 1));
        if (_greaterThan_1) {
            CharSequence _ruleImpl = this.ruleImpl(it, grammar, options, (index + 1));
            _builder.append(_ruleImpl);
            _builder.newLineIfNotEmpty();
        }
    }
    return _builder;
}
Also used : UnorderedGroup(org.eclipse.xtext.UnorderedGroup) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation)

Example 28 with UnorderedGroup

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

the class XtextValidationTest method testCheckRuleCallInUnorderedGroup_04.

@Test
public void testCheckRuleCallInUnorderedGroup_04() throws Exception {
    XtextValidator validator = get(XtextValidator.class);
    UnorderedGroup unorderedGroup = XtextFactory.eINSTANCE.createUnorderedGroup();
    RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
    TerminalRule terminalRule = XtextFactory.eINSTANCE.createTerminalRule();
    ruleCall.setRule(terminalRule);
    unorderedGroup.getElements().add(ruleCall);
    ValidatingMessageAcceptor messageAcceptor = new ValidatingMessageAcceptor(null, false, false);
    validator.setMessageAcceptor(messageAcceptor);
    validator.checkRuleCallInUnorderedGroup(ruleCall);
    messageAcceptor.validate();
}
Also used : UnorderedGroup(org.eclipse.xtext.UnorderedGroup) TerminalRule(org.eclipse.xtext.TerminalRule) RuleCall(org.eclipse.xtext.RuleCall) Test(org.junit.Test)

Example 29 with UnorderedGroup

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

the class GrammarParserTest method testPrecedencies_02.

@Test
public void testPrecedencies_02() throws Exception {
    UnorderedGroup group = (UnorderedGroup) getModel("('keyword' | 'keyword') & ('keyword' | 'keyword')");
    assertNotNull(group);
    assertEquals(2, group.getElements().size());
    assertTrue(group.getElements().get(0) instanceof Alternatives);
    assertTrue(group.getElements().get(1) instanceof Alternatives);
}
Also used : UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Alternatives(org.eclipse.xtext.Alternatives) Test(org.junit.Test)

Example 30 with UnorderedGroup

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

the class GrammarParserTest method testUnorderedGroup_01.

@Test
public void testUnorderedGroup_01() throws Exception {
    UnorderedGroup group = (UnorderedGroup) getModel("'keyword' & 'keyword'");
    assertNotNull(group);
    assertEquals(2, group.getElements().size());
}
Also used : UnorderedGroup(org.eclipse.xtext.UnorderedGroup) Test(org.junit.Test)

Aggregations

UnorderedGroup (org.eclipse.xtext.UnorderedGroup)35 AbstractElement (org.eclipse.xtext.AbstractElement)16 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)13 ParserRule (org.eclipse.xtext.ParserRule)13 Test (org.junit.Test)12 RuleCall (org.eclipse.xtext.RuleCall)11 Group (org.eclipse.xtext.Group)9 Function1 (org.eclipse.xtext.xbase.lib.Functions.Function1)9 Assignment (org.eclipse.xtext.Assignment)8 EObject (org.eclipse.emf.ecore.EObject)7 Action (org.eclipse.xtext.Action)5 Alternatives (org.eclipse.xtext.Alternatives)5 Pair (org.eclipse.xtext.xbase.lib.Pair)5 List (java.util.List)4 TerminalRule (org.eclipse.xtext.TerminalRule)4 ArrayList (java.util.ArrayList)3 AbstractRule (org.eclipse.xtext.AbstractRule)3 Keyword (org.eclipse.xtext.Keyword)3 TypeRef (org.eclipse.xtext.TypeRef)3 Token (org.antlr.runtime.Token)2