use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class FollowElementComputer method computeFollowElements.
protected void computeFollowElements(FollowElementCalculator calculator, FollowElement element, Multimap<Integer, List<AbstractElement>> visited) {
List<AbstractElement> currentState = Lists.newArrayList(element.getLocalTrace());
if (currentState.isEmpty() || currentState.get(currentState.size() - 1) != element.getGrammarElement()) {
currentState.add(element.getGrammarElement());
}
if (!visited.put(element.getLookAhead(), currentState))
return;
if (element.getLookAhead() <= 1) {
List<Integer> paramStack = element.getParamStack();
int paramIndex = computeParamStackOffset(currentState, paramStack);
for (AbstractElement abstractElement : currentState) {
paramIndex = setParamConfigAndUpdateOffset(calculator, paramStack, paramIndex, abstractElement);
Assignment ass = EcoreUtil2.getContainerOfType(abstractElement, Assignment.class);
if (ass != null)
calculator.doSwitch(ass);
else {
if (abstractElement instanceof UnorderedGroup && abstractElement == element.getGrammarElement()) {
calculator.doSwitch((UnorderedGroup) abstractElement, element.getHandledUnorderedGroupElements());
} else {
calculator.doSwitch(abstractElement);
if (GrammarUtil.isOptionalCardinality(abstractElement)) {
EObject container = abstractElement.eContainer();
if (container instanceof Group) {
Group group = (Group) container;
int idx = group.getElements().indexOf(abstractElement);
if (idx == group.getElements().size() - 1) {
if (!currentState.contains(group) && GrammarUtil.isMultipleCardinality(group)) {
calculator.doSwitch(group);
}
} else if (idx < group.getElements().size() - 1 && "?".equals(abstractElement.getCardinality())) {
// loops are fine
AbstractElement nextElement = group.getElements().get(idx + 1);
if (!currentState.contains(nextElement)) {
calculator.doSwitch(nextElement);
}
}
}
} else if (isAlternativeWithEmptyPath(abstractElement)) {
EObject container = abstractElement.eContainer();
if (container instanceof Group) {
Group group = (Group) container;
int idx = group.getElements().indexOf(abstractElement);
if (!currentState.contains(group) && idx != group.getElements().size() - 1) {
AbstractElement next = group.getElements().get(idx + 1);
if (!currentState.contains(next)) {
calculator.doSwitch(next);
}
}
}
}
}
}
}
// we need a synthetic rule call
if (element.getTrace().equals(element.getLocalTrace())) {
ParserRule parserRule = GrammarUtil.containingParserRule(element.getGrammarElement());
if (parserRule != null) {
RuleCall ruleCall = XtextFactory.eINSTANCE.createRuleCall();
ruleCall.setRule(parserRule);
calculator.doSwitch(ruleCall);
}
}
return;
}
Collection<FollowElement> followElements = parser.getFollowElements(element);
for (FollowElement newElement : followElements) {
if (newElement.getLookAhead() != element.getLookAhead() || newElement.getGrammarElement() != element.getGrammarElement()) {
if (newElement.getLookAhead() == element.getLookAhead()) {
int originalTraceSize = element.getLocalTrace().size();
List<AbstractElement> newTrace = newElement.getLocalTrace();
if (newTrace.size() > originalTraceSize) {
if (Collections.indexOfSubList(element.getLocalTrace(), newTrace.subList(originalTraceSize, newTrace.size())) != -1) {
continue;
}
}
}
computeFollowElements(calculator, newElement, visited);
}
}
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class FollowElementComputer method collectAbstractElements.
public void collectAbstractElements(Grammar grammar, EStructuralFeature feature, IFollowElementAcceptor followElementAcceptor) {
for (Grammar superGrammar : grammar.getUsedGrammars()) {
collectAbstractElements(superGrammar, feature, followElementAcceptor);
}
EClass declarator = feature.getEContainingClass();
for (ParserRule rule : GrammarUtil.allParserRules(grammar)) {
for (Assignment assignment : GrammarUtil.containedAssignments(rule)) {
if (assignment.getFeature().equals(feature.getName())) {
EClassifier classifier = GrammarUtil.findCurrentType(assignment);
EClassifier compType = EcoreUtil2.getCompatibleType(declarator, classifier);
if (compType == declarator) {
followElementAcceptor.accept(assignment);
}
}
}
}
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class SequenceFeeder method accept.
public void accept(Keyword keyword, Object value, String token, int index) {
Assignment ass = getAssignment(keyword);
EStructuralFeature feature = getFeature(ass.getFeature());
assertIndex(feature, index);
assertValue(feature, value);
ILeafNode node = getLeafNode(feature, index, index, value);
acceptKeyword(ass, keyword, value, token, index, node);
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class SequenceFeeder method accept.
public void accept(Keyword keyword, Object value, String token) {
Assignment ass = getAssignment(keyword);
EStructuralFeature feature = getFeature(ass.getFeature());
assertIndex(feature);
assertValue(feature, value);
ILeafNode node = getLeafNode(feature, value);
acceptKeyword(ass, keyword, value, token, ISemanticSequenceAcceptor.NO_INDEX, node);
}
use of org.eclipse.xtext.Assignment in project xtext-core by eclipse.
the class FeatureFinderUtil method getFeature.
/**
* @since 2.0
*/
public static EStructuralFeature getFeature(AbstractElement grammarElement, EClass owner) {
Preconditions.checkNotNull(owner);
if (grammarElement == null)
return null;
String featureName = null;
if (grammarElement instanceof Action)
featureName = ((Action) grammarElement).getFeature();
else {
Assignment ass = GrammarUtil.containingAssignment(grammarElement);
if (ass != null)
featureName = ass.getFeature();
}
if (featureName != null)
return owner.getEStructuralFeature(featureName);
return null;
}
Aggregations