Search in sources :

Example 6 with Pair

use of org.eclipse.xtext.util.Pair in project xtext-core by eclipse.

the class AbstractPDAProvider method getPDA.

/**
 * @since 2.0
 */
@Override
public IPDAState getPDA(CTX context) {
    PDAContext<CTX> ctx = createContext(context);
    ctx.start = createState(IPDAState.PDAStateType.START, null);
    ctx.stop = createState(IPDAState.PDAStateType.STOP, null);
    Set<Pair<Boolean, INFAState<?, ?>>> visited = Sets.newHashSet();
    ctx.start.followers = Sets.newHashSet();
    for (INFAState<?, ?> state : getStartFollowers(context)) {
        boolean targetCanReturn = !canEnterRuleCall(state);
        boolean targetReturning = !state.getOutgoingAfterReturn().isEmpty() && targetCanReturn;
        RuleCallStackElement stack = new RuleCallStackElement(null, null);
        IPDAState s = createState(ctx, stack, state, null, targetReturning, targetCanReturn, visited);
        if (s != null)
            ctx.start.followers.add(s);
    }
    return ctx.start;
}
Also used : IPDAState(org.eclipse.xtext.grammaranalysis.IPDAState) Pair(org.eclipse.xtext.util.Pair)

Example 7 with Pair

use of org.eclipse.xtext.util.Pair in project xtext-core by eclipse.

the class ConcreteSyntaxValidator method validateQuantities.

protected List<IConcreteSyntaxDiagnostic> validateQuantities(IQuantities quants, ISyntaxConstraint rule) {
    List<IConcreteSyntaxDiagnostic> diag = new ArrayList<IConcreteSyntaxDiagnostic>();
    Map<ISyntaxConstraint, Pair<Integer, Integer>> minmax = Maps.newHashMap();
    for (Map.Entry<EStructuralFeature, Collection<ISyntaxConstraint>> e : quants.groupByFeature().entrySet()) {
        int min = UNDEF, max = 0;
        Set<ISyntaxConstraint> involved = new HashSet<ISyntaxConstraint>();
        for (ISyntaxConstraint a : e.getValue()) {
            involved.add(a);
            int mi = intervalProvider.getMin(quants, a, involved);
            if (mi != UNDEF)
                min = min == UNDEF ? mi : mi + min;
            int ma = intervalProvider.getMax(quants, a, involved, null);
            if (ma != UNDEF && max != MAX)
                max = ma == MAX ? ma : max + ma;
            minmax.put(a, Tuples.create(mi, ma));
        }
        int actual = quants.getFeatureQuantity(e.getKey());
        if (actual < min || actual > max)
            diag.add(diagnosticProvider.createFeatureQuantityDiagnostic(rule, quants, e.getKey(), actual, min, max, involved));
    }
    // System.out.println("Validation: " + obj.toString(minmax));
    return diag;
}
Also used : ArrayList(java.util.ArrayList) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) IConcreteSyntaxDiagnostic(org.eclipse.xtext.validation.IConcreteSyntaxDiagnosticProvider.IConcreteSyntaxDiagnostic) ISyntaxConstraint(org.eclipse.xtext.validation.IConcreteSyntaxConstraintProvider.ISyntaxConstraint) ISyntaxConstraint(org.eclipse.xtext.validation.IConcreteSyntaxConstraintProvider.ISyntaxConstraint) Collection(java.util.Collection) Map(java.util.Map) Pair(org.eclipse.xtext.util.Pair) HashSet(java.util.HashSet)

Example 8 with Pair

use of org.eclipse.xtext.util.Pair in project xtext-core by eclipse.

the class StringCfg method rule.

public ProdElement rule(String rule) {
    Stack<Pair<Token, String>> tokens = lex(rule);
    if (tokens.peek().getFirst() == Token.ID) {
        String ruleName = tokens.peek().getSecond();
        tokens.pop();
        if (tokens.peek().getFirst() == Token.COLON) {
            tokens.pop();
            ProdElement ele = parseAlt(tokens);
            if (root == null)
                root = ele;
            rules.put(ruleName, ele);
            return ele;
        } else
            throw new RuntimeException("Expected ':'");
    } else
        throw new RuntimeException("Expected ID");
}
Also used : ProdElement(org.eclipse.xtext.util.formallang.StringProduction.ProdElement) Pair(org.eclipse.xtext.util.Pair)

Aggregations

Pair (org.eclipse.xtext.util.Pair)8 EObject (org.eclipse.emf.ecore.EObject)2 IPDAState (org.eclipse.xtext.grammaranalysis.IPDAState)2 AbstractModule (com.google.inject.AbstractModule)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Stack (java.util.Stack)1 Matcher (java.util.regex.Matcher)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 EPackage (org.eclipse.emf.ecore.EPackage)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 AbstractElement (org.eclipse.xtext.AbstractElement)1 AbstractRule (org.eclipse.xtext.AbstractRule)1 IGrammarAccess (org.eclipse.xtext.IGrammarAccess)1 Keyword (org.eclipse.xtext.Keyword)1 RuleCall (org.eclipse.xtext.RuleCall)1 INFAState (org.eclipse.xtext.grammaranalysis.INFAState)1 ICompositeNode (org.eclipse.xtext.nodemodel.ICompositeNode)1