use of org.eclipse.xtext.Keyword in project xtext-core by eclipse.
the class KeywordBasedValueConverter method setRule.
/**
* @throws IllegalArgumentException if the rule is not a datatype rule or does not fulfill
* the pattern <pre>RuleName: 'keyword' | 'other';</pre>
*/
@Override
public void setRule(AbstractRule rule) {
this.rule = rule;
if (!GrammarUtil.isDatatypeRule(rule))
throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
if (!(rule.getAlternatives() instanceof Alternatives) && !(rule.getAlternatives() instanceof Keyword)) {
throw new IllegalArgumentException(rule.getName() + " is not a simple keyword nor an alternative");
}
if (rule.getAlternatives() instanceof Keyword) {
keywords = ImmutableSet.of(keywordToString((Keyword) rule.getAlternatives()));
} else {
Alternatives alternatives = (Alternatives) rule.getAlternatives();
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (AbstractElement element : alternatives.getElements()) {
if (!(element instanceof Keyword)) {
throw new IllegalArgumentException(rule.getName() + "'s body does not contain an alternative of keywords");
}
builder.add(keywordToString((Keyword) element));
}
keywords = builder.build();
}
}
use of org.eclipse.xtext.Keyword in project xtext-core by eclipse.
the class AbstractSyntacticSequencer method accept.
@SuppressWarnings("deprecation")
protected void accept(ISynState emitter, INode node, RuleCallStack stack) {
switch(emitter.getType()) {
case UNASSIGNED_PARSER_RULE_ENTER:
RuleCall rc1 = (RuleCall) emitter.getGrammarElement();
delegate.enterUnassignedParserRuleCall(rc1);
stack.push(rc1);
return;
case UNASSIGNED_PARSER_RULE_EXIT:
RuleCall rc2 = (RuleCall) emitter.getGrammarElement();
delegate.leaveUnssignedParserRuleCall(rc2);
RuleCall lastRc = stack.pop();
if (lastRc != rc2) {
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.createUnexpectedStackStateDiagnostic(contexts.get(contexts.size() - 1).semanticObject, stack, lastRc, emitter));
}
return;
case UNASSIGEND_ACTION_CALL:
delegate.acceptUnassignedAction((Action) emitter.getGrammarElement());
return;
case UNASSIGEND_KEYWORD:
Keyword keyword = (Keyword) emitter.getGrammarElement();
String token = node != null ? node.getText() : keyword.getValue();
delegate.acceptUnassignedKeyword(keyword, token, (ILeafNode) node);
return;
case UNASSIGNED_DATATYPE_RULE_CALL:
RuleCall rc3 = (RuleCall) emitter.getGrammarElement();
String value3 = getUnassignedRuleCallToken(rc3, node);
delegate.acceptUnassignedDatatype(rc3, value3, (ICompositeNode) node);
return;
case UNASSIGNED_TERMINAL_RULE_CALL:
RuleCall rc4 = (RuleCall) emitter.getGrammarElement();
String value4 = getUnassignedRuleCallToken(rc4, node);
delegate.acceptUnassignedTerminal(rc4, value4, (ILeafNode) node);
return;
case ASSIGNED_ACTION_CALL:
case ASSIGNED_BOOLEAN_KEYWORD:
case ASSIGNED_CROSSREF_DATATYPE_RULE_CALL:
case ASSIGNED_CROSSREF_ENUM_RULE_CALL:
case ASSIGNED_CROSSREF_KEYWORD:
case ASSIGNED_CROSSREF_TERMINAL_RULE_CALL:
case ASSIGNED_DATATYPE_RULE_CALL:
case ASSIGNED_ENUM_RULE_CALL:
case ASSIGNED_KEYWORD:
case ASSIGNED_PARSER_RULE_CALL:
case ASSIGNED_TERMINAL_RULE_CALL:
case START:
case STOP:
case TRANSITION:
}
throw new RuntimeException("invalid state for emitting: " + emitter + " (" + emitter.getType() + ")");
}
use of org.eclipse.xtext.Keyword in project xtext-core by eclipse.
the class NodeModelSemanticSequencer method createSequence.
@Override
public void createSequence(ISerializationContext context, EObject semanticObject) {
SemanticNodeIterator ni = new SemanticNodeIterator(semanticObject);
while (ni.hasNext()) {
Triple<INode, AbstractElement, EObject> node = ni.next();
if (node.getSecond() instanceof RuleCall) {
RuleCall rc = (RuleCall) node.getSecond();
TypeRef ruleType = rc.getRule().getType();
if (ruleType == null || ruleType.getClassifier() instanceof EClass)
acceptSemantic(semanticObject, rc, node.getThird(), node.getFirst());
else if (GrammarUtil.containingCrossReference(node.getSecond()) != null) {
EStructuralFeature feature = FeatureFinderUtil.getFeature(node.getSecond(), semanticObject.eClass());
acceptSemantic(semanticObject, rc, semanticObject.eGet(feature), node.getFirst());
} else {
String strVal = NodeModelUtils.getTokenText(node.getFirst());
Object val = valueConverter.toValue(strVal, ruleNames.getQualifiedName(rc.getRule()), node.getFirst());
acceptSemantic(semanticObject, rc, val, node.getFirst());
}
} else if (node.getSecond() instanceof Keyword)
acceptSemantic(semanticObject, node.getSecond(), node.getFirst().getText(), node.getFirst());
else if (node.getSecond() instanceof Action) {
acceptSemantic(semanticObject, node.getSecond(), semanticObject, node.getFirst());
}
}
}
use of org.eclipse.xtext.Keyword in project xtext-core by eclipse.
the class EnumLiteralSerializer method serializeAssignedEnumLiteral.
@Override
public String serializeAssignedEnumLiteral(EObject context, RuleCall ruleCall, Object value, INode node, Acceptor errorAcceptor) {
Keyword nodeLit = getLiteral(node);
Keyword modelLit = getLiteral(context, ruleCall, value);
if (modelLit == null) {
if (errorAcceptor != null)
errorAcceptor.accept(diagnosticProvider.getInvalidEnumValueDiagnostic(context, ruleCall, value));
return null;
} else if (nodeLit != null && nodeLit.equals(modelLit))
return tokenUtil.serializeNode(node);
else
return modelLit.getValue();
}
use of org.eclipse.xtext.Keyword in project xtext-core by eclipse.
the class ContentAssistContextFactory method isLikelyToBeValidProposal.
protected boolean isLikelyToBeValidProposal(INode lastCompleteNode, Iterable<ContentAssistContext> contexts) {
for (ContentAssistContext context : contexts) {
for (AbstractElement element : context.getFirstSetGrammarElements()) {
if (element instanceof Keyword) {
String keywordValue = ((Keyword) element).getValue();
String lastText = ((ILeafNode) lastCompleteNode).getText();
if (keywordValue.equals(lastText))
return true;
}
}
}
return false;
}
Aggregations