public <S, P, E, T, D extends Pda<S, P>> D create(Cfg<E, T> cfg, FollowerFunction<E> ff, PdaFactory<D, S, P, ? super E> fact) { return create(cfg, ff, Functions.<E> identity(), fact); }
public <S, P, D extends Pda<S, P>> D filterOrphans(Pda<S, P> pda, PdaFactory<D, S, P, S> factory) { CyclicStackTraverser<S, P> traverser = new CyclicStackTraverser<S, P>(); return filterEdges(pda, traverser, factory); }
public <S, P> List<S> shortestPathTo(Pda<S, P> pda, Iterator<P> stack, S match) { return shortestPathTo(pda, pda.getStart(), stack, Predicates.equalTo(match), Predicates.<S> alwaysTrue()); }
protected List<ISynState> shortestStackpruningPathTo(Iterator<RuleCall> stack, Predicate<ISynState> matches, boolean includeMatch) { List<ISynState> pathTo = new PdaUtil().shortestStackpruningPathTo(getPathToTarget(), stack, matches); if (pathTo != null) return pathTo.subList(1, pathTo.size() - (includeMatch ? 0 : 1)); return null; }
protected List<ISynState> shortestPathTo(Iterator<RuleCall> stack, Predicate<ISynState> matches, boolean includeMatch) { List<ISynState> pathTo = new PdaUtil().shortestPathTo(getPathToTarget(), stack, matches); if (pathTo != null) return pathTo.subList(1, pathTo.size() - (includeMatch ? 0 : 1)); return null; }
protected Pda<ISerState, RuleCall> createPDA(Action action) { SerializerActionCfg cfg = new SerializerActionCfg(action); SerializerActionFollowerFunction ff = new SerializerActionFollowerFunction(cfg, action); SerializerPDAElementFactory fact = new SerializerPDAElementFactory(); Pda<ISerState, RuleCall> actionpda = pdaUtil.create(cfg, ff, fact); SerializerPDAGetToken getToken = new SerializerPDAGetToken(); Pda<ISerState, RuleCall> expandedpda = pdaUtil.expand(actionpda, new ExpandRuleCalls(), getToken, fact); Pda<ISerState, RuleCall> filteredpda = pdaUtil.filterOrphans(expandedpda, new SerializerPDACloneFactory()); return filteredpda; }
followers.put(state, f); if (f.size() == 1) filterUnambiguousPaths(pda, f.get(0), dist, followers); return; filterUnambiguousPaths(pda, follower, dist, followers);
public <S, P> List<S> shortestStackpruningPathTo(Pda<S, P> pda, Iterator<P> stack, Predicate<S> matches) { return shortestStackpruningPathTo(pda, pda.getStart(), stack, matches, Predicates.<S> alwaysTrue()); }
public <S, P> long distanceTo(Pda<S, P> pda, Iterable<S> starts, Iterator<P> stack, Predicate<S> matches, Predicate<S> canPass) { TraceItem<S, P> trace = trace(pda, starts, stack, matches, canPass); if (trace != null) return trace.size(); return UNREACHABLE; }
protected Pda<ISerState, RuleCall> createPDA(EObject context, EClass type) { Pda<ISerState, RuleCall> contextPda = pdaProvider.getContextPDA(context); Pda<ISerState, RuleCall> contextTypePda = null; if (contextProvider.getTypesForContext(context).size() > 1) { TypeFilter typeFilter = newTypeFilter(type); SerializerPDACloneFactory factory = new SerializerPDACloneFactory(); contextTypePda = new PdaUtil().filterEdges(contextPda, typeFilter, factory); } else contextTypePda = contextPda; return contextTypePda; }
protected Pda<ISerState, RuleCall> createPDA(ParserRule rule) { SerializerParserRuleCfg cfg = new SerializerParserRuleCfg(rule); SerializerParserRuleFollowerFunction ff = new SerializerParserRuleFollowerFunction(cfg, rule); Pda<ISerState, RuleCall> pda = pdaUtil.create(cfg, ff, new SerializerPDAElementFactory()); return pdaUtil.filterOrphans(pda, new SerializerPDACloneFactory()); }
public List<AbstractElementAlias> getAmbiguousSyntaxes() { if (ambiguousSyntaxes != null) return ambiguousSyntaxes; if (!isSyntacticallyAmbiguous()) return ambiguousSyntaxes = Collections.emptyList(); ambiguousSyntaxes = Lists.newArrayList(); Nfa<ISynState> nfa = new PdaUtil().filterUnambiguousPaths(getPathToTarget()); nfa = new NfaUtil().filter(nfa, new Filter()); AbstractElementAlias syntax = new NfaToProduction().nfaToGrammar(nfa, new GetGrammarElement(), new GrammarAliasFactory()); if (syntax instanceof GroupAlias) { GroupAlias group = (GroupAlias) syntax; for (AbstractElementAlias child : group.getChildren()) if (child.isMany() || child.isOptional() || child instanceof AlternativeAlias) ambiguousSyntaxes.add(child); } else ambiguousSyntaxes.add(syntax); return ambiguousSyntaxes; }
protected <S, P> TraceItem<S, P> trace(Pda<S, P> pda, Iterable<S> starts, Iterator<P> stack, Predicate<S> matches, Predicate<S> canPass) { StackItem<P> stackItem = createStack(stack); List<TraceItem<S, P>> current = Lists.newArrayList(); Set<S> visited = Sets.newLinkedHashSet(starts);
public <S, P> boolean canReach(Pda<S, P> pda, S state, Iterator<P> stack, Predicate<S> matches, Predicate<S> canPass) { return distanceTo(pda, Collections.singleton(state), stack, matches, canPass) != UNREACHABLE; }
S f_new = idstates.get(f_old); if (f_new == null) { idstates.put(f_old, f_new = clone(f_old, sub, result, tokens, fact, identity)); followers.putAll(f_new, pda.getFollowers(f_old)); idstates.put(s_old, s_new = clone(s_old, pda, result, tokens, fact, identity)); followers.putAll(s_new, pda.getFollowers(s_old));
return factory == null ? null : factory.create(pda.getStart(), pda.getStop()); MappedComparator<S, Integer> distanceComp = new MappedComparator<S, Integer>(distances); trace.push(newItem(pda, distanceComp, distances, pda.getStart(), previous)); Multimap<S, S> edges = LinkedHashMultimap.create(); HashSet<S> states = Sets.newLinkedHashSet(); if (trace.push(newItem(pda, distanceComp, distances, next, item))) continue ROOT;
followers.put(state, f); if (f.size() == 1) filterUnambiguousPaths(pda, f.get(0), dist, followers); return; filterUnambiguousPaths(pda, follower, dist, followers);
public <S, P> List<S> shortestStackpruningPathTo(Pda<S, P> pda, Iterator<P> stack, S matches) { return shortestStackpruningPathTo(pda, pda.getStart(), stack, Predicates.equalTo(matches), Predicates.<S> alwaysTrue()); }
public <S, P> List<S> shortestPathTo(Pda<S, P> pda, S start, Iterator<P> stack, Predicate<S> matches, Predicate<S> canPass) { TraceItem<S, P> trace = trace(pda, Collections.singleton(start), stack, matches, canPass); if (trace != null) return trace.asList(); return null; }
protected <S, P> TraceItem<S, P> trace(Pda<S, P> pda, Iterable<S> starts, Iterator<P> stack, Predicate<S> matches, Predicate<S> canPass) { StackItem<P> stackItem = createStack(stack); List<TraceItem<S, P>> current = Lists.newArrayList(); Set<S> visited = Sets.newHashSet(starts);