Search in sources :

Example 26 with AbstractElement

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();
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement)

Example 27 with AbstractElement

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;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement)

Example 28 with AbstractElement

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;
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement) INFAState(org.eclipse.xtext.grammaranalysis.INFAState) IPDAState(org.eclipse.xtext.grammaranalysis.IPDAState) Pair(org.eclipse.xtext.util.Pair)

Example 29 with AbstractElement

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();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) AbstractElement(org.eclipse.xtext.AbstractElement) Alternatives(org.eclipse.xtext.Alternatives) RuleCall(org.eclipse.xtext.RuleCall)

Example 30 with AbstractElement

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);
}
Also used : AbstractElement(org.eclipse.xtext.AbstractElement)

Aggregations

AbstractElement (org.eclipse.xtext.AbstractElement)126 EObject (org.eclipse.emf.ecore.EObject)39 AbstractRule (org.eclipse.xtext.AbstractRule)34 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)31 RuleCall (org.eclipse.xtext.RuleCall)26 ParserRule (org.eclipse.xtext.ParserRule)18 Grammar (org.eclipse.xtext.Grammar)17 EList (org.eclipse.emf.common.util.EList)15 Assignment (org.eclipse.xtext.Assignment)15 Test (org.junit.Test)14 Group (org.eclipse.xtext.Group)13 UnorderedGroup (org.eclipse.xtext.UnorderedGroup)13 List (java.util.List)12 ArrayList (java.util.ArrayList)11 XtextResource (org.eclipse.xtext.resource.XtextResource)11 Action (org.eclipse.xtext.Action)10 TerminalRule (org.eclipse.xtext.TerminalRule)10 Alternatives (org.eclipse.xtext.Alternatives)9 EClassifier (org.eclipse.emf.ecore.EClassifier)8 InternalEObject (org.eclipse.emf.ecore.InternalEObject)8