use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class BaseContentAssistParser method getEntryGrammarElement.
protected AbstractElement getEntryGrammarElement(ICompositeNode entryPoint) {
EObject grammarElement = entryPoint.getGrammarElement();
if (grammarElement instanceof RuleCall) {
AbstractRule rule = ((RuleCall) grammarElement).getRule();
if (rule instanceof ParserRule) {
if (!GrammarUtil.isMultipleCardinality(rule.getAlternatives())) {
grammarElement = rule.getAlternatives();
}
}
} else if (grammarElement instanceof ParserRule) {
grammarElement = ((ParserRule) grammarElement).getAlternatives();
} else if (grammarElement instanceof CrossReference) {
grammarElement = GrammarUtil.containingAssignment(grammarElement);
}
AbstractElement result = (AbstractElement) grammarElement;
if (result instanceof Action) {
return getEntryGrammarElement((ICompositeNode) entryPoint.getFirstChild());
}
return result;
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class FirstSetComputationTest method assertFirstSet.
protected void assertFirstSet(String expectation, AbstractRule rule) {
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
ruleCall.setRule(rule);
List<AbstractElement> firstSet = AntlrGrammarGenUtil.getFirstSet(ruleCall);
StringBuilder actual = new StringBuilder();
GrammarElementTitleSwitch stringifier = new GrammarElementTitleSwitch();
for (int i = 0; i < firstSet.size(); i++) {
if (i != 0)
actual.append(", ");
actual.append(stringifier.apply(firstSet.get(i)));
}
assertEquals(expectation, actual.toString());
}
use of org.eclipse.xtext.RuleCall in project xtext-core by eclipse.
the class ContextPDAProvider method collectExtracted.
protected void collectExtracted(ISerState orig, Collection<? extends ISerState> precedents, SerializerPDAState copy, Map<Pair<AbstractElement, SerStateType>, SerializerPDAState> oldToNew, final CallStack inTop, SerializerPDAState start) {
for (ISerState pre : precedents) {
CallStack top = inTop;
AbstractElement element = pre.getGrammarElement();
switch(pre.getType()) {
case START:
if (top.call == null)
connect(start, copy);
continue;
case POP:
top = new CallStack(top, (RuleCall) element);
if (top.isLoop())
continue;
break;
case PUSH:
if (top.call == null) {
connect(start, copy);
continue;
} else if (top.call == element) {
top = top.parent;
} else {
continue;
}
default:
break;
}
Pair<AbstractElement, SerStateType> key = Tuples.create(element, pre.getType());
SerializerPDAState pre2 = oldToNew.get(key);
if (pre2 == null) {
pre2 = new SerializerPDAState(element, pre.getType());
oldToNew.put(key, pre2);
}
if (GrammarUtil.isAssignedAction(pre.getGrammarElement())) /* && pre.getType() != STOP */
{
Set<ISerState> entries = collectPushForAction(pre);
collectExtracted(pre, entries, pre2, oldToNew, top, start);
} else {
if (top.visited.add(pre))
collectExtracted(pre, pre.getPrecedents(), pre2, oldToNew, top, start);
}
connect(pre2, copy);
}
}
use of org.eclipse.xtext.RuleCall 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.RuleCall 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());
}
}
}
Aggregations