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;
}
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;
}
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();
}
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);
}
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());
}
Aggregations