org.eclipse.xtext.Alternatives Java Examples

The following examples show how to use org.eclipse.xtext.Alternatives. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String dataTypeEbnf2(final AbstractElement it, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _dataTypeEbnf2((Alternatives)it, supportActions);
  } else if (it instanceof Group) {
    return _dataTypeEbnf2((Group)it, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _dataTypeEbnf2((UnorderedGroup)it, supportActions);
  } else if (it instanceof Keyword) {
    return _dataTypeEbnf2((Keyword)it, supportActions);
  } else if (it instanceof RuleCall) {
    return _dataTypeEbnf2((RuleCall)it, supportActions);
  } else if (it != null) {
    return _dataTypeEbnf2(it, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, supportActions).toString());
  }
}
 
Example #2
Source File: AbstractAntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected String ebnf2(final AbstractElement it, final AntlrOptions options, final boolean supportActions) {
  if (it instanceof Alternatives) {
    return _ebnf2((Alternatives)it, options, supportActions);
  } else if (it instanceof Group) {
    return _ebnf2((Group)it, options, supportActions);
  } else if (it instanceof UnorderedGroup) {
    return _ebnf2((UnorderedGroup)it, options, supportActions);
  } else if (it instanceof Action) {
    return _ebnf2((Action)it, options, supportActions);
  } else if (it instanceof Assignment) {
    return _ebnf2((Assignment)it, options, supportActions);
  } else if (it instanceof EnumLiteralDeclaration) {
    return _ebnf2((EnumLiteralDeclaration)it, options, supportActions);
  } else if (it instanceof Keyword) {
    return _ebnf2((Keyword)it, options, supportActions);
  } else if (it instanceof RuleCall) {
    return _ebnf2((RuleCall)it, options, supportActions);
  } else if (it != null) {
    return _ebnf2(it, options, supportActions);
  } else {
    throw new IllegalArgumentException("Unhandled parameter types: " +
      Arrays.<Object>asList(it, options, supportActions).toString());
  }
}
 
Example #3
Source File: MatcherState.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean isOptional(AbstractElement ele) {
	if (GrammarUtil.isOptionalCardinality(ele) || ele instanceof Action)
		return true;
	if (ele instanceof CompoundElement) {
		List<EObject> children = ele.eContents();
		if (children.isEmpty() && getBuilder().filter(ele))
			return true;
		if (ele instanceof Alternatives) {
			for (AbstractElement a : ((Alternatives) ele).getElements())
				if (isOptional(a))
					return true;
			return false;
		}
		for (EObject e : children)
			if (e instanceof AbstractElement && !isOptional((AbstractElement) e))
				return false;
		return true;
	} else
		return false;
}
 
Example #4
Source File: TerminalRuleToLexerBody.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public String caseAlternatives(Alternatives object) {
	result.append('(');
	boolean first = true;
	for(AbstractElement elem: object.getElements()) {
		if (!first) result.append('|');
		first = false;
		doSwitch(elem);
	}
	result.append(')').append(Strings.emptyIfNull(object.getCardinality()));
	return "";
}
 
Example #5
Source File: GrammarTest.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Test public void testExampleGrammar() throws Exception {
	with(Ecore2XtextTestStandaloneSetup.class);
	Grammar grammar = getGrammarAccess().getGrammar();
	EList<AbstractMetamodelDeclaration> metamodelDeclarations = grammar.getMetamodelDeclarations();
	assertEquals(2, metamodelDeclarations.size());
	
	AbstractRule intDatatypeRule = GrammarUtil.findRuleForName(grammar, "INT0");
	assertNotNull(intDatatypeRule);

	AbstractRule concrete0Rule = GrammarUtil.findRuleForName(grammar, "Concrete0");
	assertNotNull(concrete0Rule);
	
	AbstractRule abstractRule = GrammarUtil.findRuleForName(grammar, "Abstract");
	AbstractElement alternatives = abstractRule.getAlternatives();
	assertTrue(alternatives instanceof Alternatives);
	assertEquals(3, ((Alternatives) alternatives).getElements().size());
	assertTrue(GrammarUtil.containedAssignments(abstractRule).isEmpty());
	
	checkConcreteImplRule(grammar, "Concrete0_Impl");
	checkConcreteImplRule(grammar, "Concrete1_Impl");
	
	ParserRule rootRule = (ParserRule) grammar.getRules().get(0);
	assertEquals("Root", rootRule.getName());
	List<Assignment> assignments = GrammarUtil.containedAssignments(rootRule);
	assertEquals(4, assignments.size());
	assertEquals("name", assignments.get(0).getFeature());
	assertEquals("classes", assignments.get(1).getFeature());
	assertEquals("+=", assignments.get(1).getOperator());
	assertEquals("classes", assignments.get(2).getFeature());
	assertEquals("+=", assignments.get(2).getOperator());
	assertEquals("concrete0", assignments.get(3).getFeature());
	assertEquals("=", assignments.get(3).getOperator());
}
 
Example #6
Source File: CfgAdapter.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<AbstractElement> getAlternativeChildren(AbstractElement ele) {
	switch (ele.eClass().getClassifierID()) {
		case XtextPackage.ALTERNATIVES:
			return ((Alternatives) ele).getElements();
		default:
			return null;
	}
}
 
Example #7
Source File: AbstractBacktrackingContentAssistTestLanguageProposalProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public void completeAdditive_Argument(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
	completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(0)), context, acceptor);
	completeRuleCall(((RuleCall)((Alternatives)assignment.getTerminal()).getElements().get(1)), context, acceptor);
}
 
Example #8
Source File: AssignmentFinderTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #9
Source File: SemverGrammarAccess.java    From n4js with Eclipse Public License 1.0 votes vote down vote up
public Alternatives getAlternatives_0() { return cAlternatives_0; } 
Example #10
Source File: XtextGrammarTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #11
Source File: RegularExpressionGrammarAccess.java    From n4js with Eclipse Public License 1.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #12
Source File: ReferenceGrammarTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getWertAlternatives_0() { return cWertAlternatives_0; } 
Example #13
Source File: XtextGrammarTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives_0_0_2() { return cAlternatives_0_0_2; } 
Example #14
Source File: EnumAndReferenceTestLanguageGrammarAccess.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #15
Source File: XtypeGrammarAccess.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #16
Source File: Bug287988TestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #17
Source File: KeywordsUiTestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #18
Source File: Bug332217TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #19
Source File: SemverGrammarAccess.java    From n4js with Eclipse Public License 1.0 votes vote down vote up
public Alternatives getAlternatives_1() { return cAlternatives_1; } 
Example #20
Source File: UnassignedTextTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #21
Source File: Bug303200TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #22
Source File: FileAwareTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives_3() { return cAlternatives_3; } 
Example #23
Source File: RegionAccessTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #24
Source File: DomainModelTestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #25
Source File: Bug286935TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #26
Source File: EnumRulesTestLanguageGrammarAccess.java    From xtext-extras with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #27
Source File: XtextGrammarTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getCardinalityAlternatives_1_0() { return cCardinalityAlternatives_1_0; } 
Example #28
Source File: XtextGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives() { return cAlternatives; } 
Example #29
Source File: Bug348427TestLanguageGrammarAccess.java    From xtext-eclipse with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives_1() { return cAlternatives_1; } 
Example #30
Source File: BeeLangTestLanguageGrammarAccess.java    From xtext-core with Eclipse Public License 2.0 votes vote down vote up
public Alternatives getAlternatives_0() { return cAlternatives_0; }