use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class TreeConstState method getStatus.
public Status getStatus() {
if (distances == null) {
AbstractElement rootEle = containingRule(element).getAlternatives();
builder.getState(rootEle).initStatus();
}
return getStatusInternal();
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class TreeConstState method getEndDistances.
protected Map<TreeConstState, Integer> getEndDistances() {
AbstractElement rootEle = containingRule(element).getAlternatives();
TreeConstState root = builder.getState(rootEle);
if (root.endDistances == null)
root.endDistances = Maps.newLinkedHashMap();
return root.endDistances;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractPDAProvider method createState.
/**
* @since 2.0
*/
protected PDAState createState(PDAContext<CTX> ctx, RuleCallStackElement stack, INFAState<?, ?> fromNfa, EClass constructedType, boolean returning, boolean canReturn, Set<Pair<Boolean, INFAState<?, ?>>> visited) {
Set<Pair<Boolean, INFAState<?, ?>>> visited2 = Sets.newHashSet();
if (stack == null || !canReachContextEnd(ctx, stack.cloneWithoutVisited(), fromNfa, constructedType, returning, canReturn, visited2))
return null;
if (constructedType == null)
constructedType = getConstructedType(fromNfa.getGrammarElement());
AbstractElement ge = fromNfa.getGrammarElement();
PDAState result = null;
if (canEnterRuleCall(fromNfa)) {
if (returning) {
if ((result = ctx.ruleCallExit.get(fromNfa)) == null)
ctx.ruleCallExit.put(fromNfa, result = createState(PDAStateType.RULECALL_EXIT, ge));
} else {
if ((result = ctx.ruleCallEnter.get(fromNfa)) == null)
ctx.ruleCallEnter.put(fromNfa, result = createState(PDAStateType.RULECALL_ENTER, ge));
}
} else {
if ((result = ctx.elements.get(fromNfa)) == null)
ctx.elements.put(fromNfa, result = createState(PDAStateType.ELEMENT, ge));
}
if (!visited.add(Tuples.<Boolean, INFAState<?, ?>>create(returning, fromNfa)))
return result;
if (!returning && canEnterRuleCall(fromNfa)) {
if (stack.hasEnteredTwice(fromNfa))
return result;
stack = stackPush(stack, fromNfa);
visited = Sets.newHashSet();
}
if (result.followers == null || result.followers == Collections.EMPTY_SET) {
result.followers = Sets.newHashSet();
}
if (isFinalState(ctx.context, fromNfa, returning, canReturn))
result.followers.add(ctx.stop);
for (INFAState<?, ?> follower : getFollowers(ctx.context, fromNfa, returning, canReturn)) {
boolean folCanReturn = !canEnterRuleCall(follower);
boolean folReturning = follower.hasOutgoingRuleCall() && folCanReturn;
PDAState r = createState(ctx, stack, follower, constructedType, folReturning, folCanReturn, visited);
if (r != null)
result.followers.add(r);
}
if (canReturn && fromNfa.isEndState() && stack != null && stack.getRuleCall() != null) {
visited = Sets.newHashSet();
PDAState r = createState(ctx, stack.getParent(), stack.getRuleCall(), constructedType, true, true, visited);
if (r != null)
result.followers.add(r);
}
return result;
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class KeywordAlternativeConverter method setRule.
/**
* @throws IllegalArgumentException if the rule is not a datatype rule or does not match
* the pattern <pre>RuleName: 'keyword' | 'other';</pre>
*/
@Override
public void setRule(AbstractRule rule) {
if (!GrammarUtil.isDatatypeRule(rule))
throw new IllegalArgumentException(rule.getName() + " is not a data type rule");
if (!(rule.getAlternatives() instanceof Alternatives)) {
if (rule.getAlternatives() instanceof RuleCall) {
delegateRule = ((RuleCall) rule.getAlternatives()).getRule();
keywords = Collections.emptySet();
return;
}
throw mismatchedRuleBody(rule);
}
Alternatives alternatives = (Alternatives) rule.getAlternatives();
ImmutableSet.Builder<String> builder = ImmutableSet.builder();
for (AbstractElement element : alternatives.getElements()) {
processElement(element, rule, builder);
}
keywords = builder.build();
}
use of org.eclipse.xtext.AbstractElement in project xtext-core by eclipse.
the class AbstractFormattingConfig method addLocatorSemantic.
protected void addLocatorSemantic(ElementLocator locator) {
List<AbstractElement> before = getAbstractElements(locator.before);
List<AbstractElement> after = getAbstractElements(locator.after);
if (before != null && after != null)
for (AbstractElement b : before) for (AbstractElement a : after) addLocatorSemantic(locator, b, a);
else if (before != null)
for (AbstractElement b : before) addLocatorSemantic(locator, b, null);
else if (after != null)
for (AbstractElement a : after) addLocatorSemantic(locator, null, a);
}
Aggregations