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;
}
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;
}
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");
}
Aggregations