use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.
the class AbstractSyntacticSequencer method acceptNode.
protected void acceptNode(INode node) {
Object ge = node.getGrammarElement();
if (ge instanceof Keyword)
acceptUnassignedKeyword((Keyword) ge, node.getText(), (ILeafNode) node);
else if (ge instanceof RuleCall) {
RuleCall rc = (RuleCall) ge;
if (rc.getRule() instanceof TerminalRule)
acceptUnassignedTerminal(rc, node.getText(), (ILeafNode) node);
else if (rc.getRule() instanceof ParserRule) {
StringBuilder text = new StringBuilder();
for (ILeafNode leaf : node.getLeafNodes()) if (text.length() > 0 || !leaf.isHidden())
text.append(leaf.getText());
acceptUnassignedDatatype(rc, text.toString(), (ICompositeNode) node);
} else if (rc.getRule() instanceof EnumRule)
acceptUnassignedEnum(rc, node.getText(), (ICompositeNode) node);
} else if (ge instanceof Action)
acceptUnassignedAction((Action) ge);
else
throw new RuntimeException("Unexpected grammar element: " + node.getGrammarElement());
}
use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.
the class NodeModelSemanticSequencer method acceptSemantic.
protected boolean acceptSemantic(EObject semanticObject, AbstractElement ele, Object value, INode node) {
Assignment ass = GrammarUtil.containingAssignment(ele);
int index = -2;
if (ass != null) {
EStructuralFeature feat = semanticObject.eClass().getEStructuralFeature(ass.getFeature());
if (feat != null) {
if (feat.isMany())
index = ((List<?>) semanticObject.eGet(feat)).indexOf(value);
else
index = -1;
}
}
String token = node.getText().trim();
if (ele instanceof Action) {
if (((Action) ele).getFeature() != null) {
if (sequenceAcceptor.enterAssignedAction((Action) ele, (EObject) value, (ICompositeNode) node)) {
createSequence(ele, (EObject) value);
sequenceAcceptor.leaveAssignedAction((Action) ele, (EObject) value);
}
return true;
}
} else if (GrammarUtil.containingCrossReference(ele) != null) {
if (ele instanceof RuleCall) {
RuleCall rc = (RuleCall) ele;
if (rc.getRule() instanceof ParserRule) {
sequenceAcceptor.acceptAssignedCrossRefDatatype(rc, token, (EObject) value, index, (ICompositeNode) node);
return true;
}
if (rc.getRule() instanceof TerminalRule) {
sequenceAcceptor.acceptAssignedCrossRefTerminal(rc, token, (EObject) value, index, (ILeafNode) node);
return true;
}
if (rc.getRule() instanceof EnumRule) {
sequenceAcceptor.acceptAssignedCrossRefEnum(rc, token, (EObject) value, index, (ICompositeNode) node);
return true;
}
// } else if (ele instanceof Keyword) {
// acceptor.acceptAssignedCrossRefKeyword((Keyword) ele, token, (EObject) value, index,(ILeafNode) node);
// return true;
}
} else if (ass != null) {
if (ele instanceof RuleCall) {
RuleCall rc = (RuleCall) ele;
if (rc.getRule() instanceof ParserRule) {
if (rc.getRule().getType().getClassifier() instanceof EClass) {
if (sequenceAcceptor.enterAssignedParserRuleCall(rc, (EObject) value, (ICompositeNode) node)) {
createSequence(rc.getRule(), (EObject) value);
sequenceAcceptor.leaveAssignedParserRuleCall(rc, (EObject) value);
}
} else
sequenceAcceptor.acceptAssignedDatatype(rc, token, value, index, (ICompositeNode) node);
return true;
}
if (rc.getRule() instanceof TerminalRule) {
sequenceAcceptor.acceptAssignedTerminal(rc, token, value, index, (ILeafNode) node);
return true;
}
if (rc.getRule() instanceof EnumRule) {
sequenceAcceptor.acceptAssignedEnum(rc, token, value, index, (ICompositeNode) node);
return true;
}
} else if (ele instanceof Keyword) {
if (GrammarUtil.isBooleanAssignment(ass))
sequenceAcceptor.acceptAssignedKeyword((Keyword) ele, token, true, index, (ILeafNode) node);
else
sequenceAcceptor.acceptAssignedKeyword((Keyword) ele, token, (String) value, index, (ILeafNode) node);
return true;
}
}
return false;
}
use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.
the class AntlrGrammarGenerator method compileReturns.
protected CharSequence compileReturns(final AbstractRule it, final AntlrOptions options) {
CharSequence _switchResult = null;
boolean _matched = false;
if (it instanceof EnumRule) {
_matched = true;
_switchResult = "[Enumerator current=null]";
}
if (!_matched) {
if (it instanceof ParserRule) {
boolean _isDatatypeRule = GrammarUtil.isDatatypeRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule) it)));
if (_isDatatypeRule) {
_matched = true;
_switchResult = "[AntlrDatatypeRuleToken current=new AntlrDatatypeRuleToken()]";
}
}
}
if (!_matched) {
if (it instanceof ParserRule) {
boolean _isEObjectFragmentRule = GrammarUtil.isEObjectFragmentRule(AntlrGrammarGenUtil.<ParserRule>getOriginalElement(((ParserRule) it)));
if (_isEObjectFragmentRule) {
_matched = true;
StringConcatenation _builder = new StringConcatenation();
_builder.append("[");
String _currentType = this.getCurrentType();
_builder.append(_currentType);
_builder.append(" current=in_current]");
_switchResult = _builder;
}
}
}
if (!_matched) {
if (it instanceof ParserRule) {
_matched = true;
StringConcatenation _builder = new StringConcatenation();
_builder.append("[");
String _currentType = this.getCurrentType();
_builder.append(_currentType);
_builder.append(" current=null]");
_switchResult = _builder;
}
}
if (!_matched) {
throw new IllegalStateException(("Unexpected rule: " + it));
}
return _switchResult;
}
use of org.eclipse.xtext.EnumRule in project xtext-xtend by eclipse.
the class XtendAntlrGrammarGeneratorHelper method getTokens.
public LinkedHashSet<String> getTokens(final Grammar it) {
final LinkedHashSet<String> tokens = CollectionLiterals.<String>newLinkedHashSet();
List<ParserRule> _allParserRules = GrammarUtil.allParserRules(it);
List<EnumRule> _allEnumRules = GrammarUtil.allEnumRules(it);
Iterable<AbstractRule> _plus = Iterables.<AbstractRule>concat(_allParserRules, _allEnumRules);
for (final AbstractRule rule : _plus) {
this.collectTokens(rule, tokens);
}
return tokens;
}
use of org.eclipse.xtext.EnumRule in project xtext-core by eclipse.
the class GrammarParserTest method testEnum_05.
@Test
public void testEnum_05() throws Exception {
String modelAsString = "grammar TestLanguage with org.eclipse.xtext.common.Terminals\n" + "import 'classpath:/org/eclipse/xtext/enumrules/enums.ecore'\n" + "generate testLanguage 'http://www.eclipse.org/2009/tmf/xtext/AbstractEnumRulesTest/TestEnum/5'\n" + "Model: enumValue=ExistingEnum;\n" + "enum ExistingEnum: SameName = 'value';";
Grammar grammar = (Grammar) getModel(modelAsString);
assertTrue(grammar.eResource().getErrors().toString(), grammar.eResource().getErrors().isEmpty());
checkEnums(grammar);
EPackage pack = grammar.getMetamodelDeclarations().get(0).getEPackage();
assertEquals("http://www.eclipse.org/2009/tmf/xtext/EnumRulesTestLanguage/imported", pack.getNsURI());
EEnum eEnum = (EEnum) pack.getEClassifier("ExistingEnum");
assertNotNull(eEnum);
assertEquals(3, eEnum.getELiterals().size());
EEnumLiteral value = eEnum.getELiterals().get(0);
assertEquals(ExistingEnum.SAME_NAME.getName(), value.getName());
assertEquals(ExistingEnum.SAME_NAME.getValue(), value.getValue());
assertEquals(ExistingEnum.SAME_NAME.getLiteral(), value.getLiteral());
EnumRule rule = (EnumRule) grammar.getRules().get(1);
assertEquals(eEnum, rule.getType().getClassifier());
EnumLiteralDeclaration decl = (EnumLiteralDeclaration) rule.getAlternatives();
assertEquals(value, decl.getEnumLiteral());
assertNotNull(decl.getLiteral());
assertEquals("value", decl.getLiteral().getValue());
}
Aggregations