public SynAbsorberNfaAdapter(ISynAbsorberState start) { super(); this.start = start; this.stop = new NfaUtil().find(this, new Predicate<ISynAbsorberState>() { public boolean apply(ISynAbsorberState input) { return input.getType().isStop(); } }); }
@Override public boolean equals(Object obj) { if (obj == null || obj.getClass() != getClass()) return false; return new NfaUtil().equalsIgnoreOrder(this, (SerializerPDA) obj); }
public <S, P, R, D extends Pda<S, P>> D filterEdges(Pda<S, P> pda, Traverser<? super Pda<S, P>, S, R> traverser, PdaFactory<D, S, P, S> factory) { Map<S, Integer> distances = new NfaUtil().distanceToFinalStateMap(pda); return filterEdges(pda, traverser, distances, factory); }
public String format(Pda<STATE, STACKITEM> pda) { STATE start = pda.getStart(); List<String> result = Lists.newArrayList(); for (STATE s : new NfaUtil().collect(pda)) if (s != start) { String str = format(pda, s); if (str != null) result.add(str); } Collections.sort(result); String startstring = format(pda, start); if (startstring != null) result.add(0, startstring); return Joiner.on('\n').join(result); }
public String format(Pda<STATE, STACKITEM> pda) { STATE start = pda.getStart(); List<String> result = Lists.newArrayList(); for (STATE s : new NfaUtil().collect(pda)) if (s != start) { String str = format(pda, s); if (str != null) result.add(str); } Collections.sort(result); String startstring = format(pda, start); if (startstring != null) result.add(0, startstring); return Joiner.on('\n').join(result); }
public <S extends Comparable<S>> Nfa<S> sort(Nfa<S> nfa) { Map<S, List<S>> followerMap = Maps.newLinkedHashMap(); for (S state : new NfaUtil().collect(nfa)) { ArrayList<S> followers = Lists.newArrayList(nfa.getFollowers(state)); Collections.sort(followers); followerMap.put(state, followers); } return new NFAImpl<S>(nfa.getStart(), nfa.getStop(), followerMap); }
public <S> Nfa<S> sort(Nfa<S> nfa, Comparator<S> comparator) { Map<S, List<S>> followerMap = Maps.newHashMap(); for (S state : new NfaUtil().collect(nfa)) { ArrayList<S> followers = Lists.newArrayList(nfa.getFollowers(state)); Collections.sort(followers, comparator); followerMap.put(state, followers); } return new NFAImpl<S>(nfa.getStart(), nfa.getStop(), followerMap); }
public <S> Nfa<S> sort(Nfa<S> nfa, Comparator<S> comparator) { Map<S, List<S>> followerMap = Maps.newLinkedHashMap(); for (S state : new NfaUtil().collect(nfa)) { ArrayList<S> followers = Lists.newArrayList(nfa.getFollowers(state)); Collections.sort(followers, comparator); followerMap.put(state, followers); } return new NFAImpl<S>(nfa.getStart(), nfa.getStop(), followerMap); }
public <S extends Comparable<S>> Nfa<S> sort(Nfa<S> nfa) { Map<S, List<S>> followerMap = Maps.newHashMap(); for (S state : new NfaUtil().collect(nfa)) { ArrayList<S> followers = Lists.newArrayList(nfa.getFollowers(state)); Collections.sort(followers); followerMap.put(state, followers); } return new NFAImpl<S>(nfa.getStart(), nfa.getStop(), followerMap); }
protected ISerState findState(ISerializationContext ctx, AbstractElement ele) { Pda<ISerState, RuleCall> pda = pdas.get(ctx); return new NfaUtil().find(pda, s -> s.getGrammarElement() == ele); }
protected void initOrderIDs(Nfa<ISemState> nfa) { for (ISemState state : new NfaUtil().collect(nfa)) if (state.getAssignedGrammarElement() != null) ((SemState) state).orderID = getElementID(state.getAssignedGrammarElement()); }
protected void initContentValidationNeeded(EClass clazz, Nfa<ISemState> nfa) { Multimap<EStructuralFeature, AbstractElement> assignments = HashMultimap.create(); Set<ISemState> states = new NfaUtil().collect(nfa); for (ISemState state : states) if (state.getFeature() != null) assignments.put(state.getFeature(), state.getAssignedGrammarElement()); boolean[] validationNeeded = new boolean[clazz.getFeatureCount()]; for (EStructuralFeature feature : clazz.getEAllStructuralFeatures()) validationNeeded[clazz.getFeatureID(feature)] = isContentValidationNeeded(assignments.get(feature)); for (ISemState state : states) if (state.getFeature() != null && validationNeeded[state.getFeatureID()]) ((SemState) state).contentValidationNeeded = Lists.newArrayList(assignments.get(state.getFeature())); else ((SemState) state).contentValidationNeeded = Collections.emptyList(); }
protected Nfa<ProdElement> getParameterNfa(String syntax) { AssignedProduction prod = new AssignedProduction(syntax); FollowerFunctionImpl<ProdElement, String> ff = new FollowerFunctionImpl<ProdElement, String>(prod); ProdElement start = prod.new ProdElement(ElementType.TOKEN); ProdElement stop = prod.new ProdElement(ElementType.TOKEN); Nfa<ProdElement> result = new NfaUtil().create(prod, ff, start, stop); return result; }
protected void draw(Digraph result, Nfa<STATE> nfa) { for (STATE s : new NfaUtil().collect(nfa)) { result.add(create(result, nfa, s)); for (STATE f : nfa.getFollowers(s)) result.add(create(result, nfa, s, f)); } }
protected void draw(Digraph result, Pda<STATE, STACKITEM> pda) { for (STATE s : new NfaUtil().collect(pda)) { result.add(create(result, pda, s)); for (STATE f : pda.getFollowers(s)) result.add(create(result, pda, s, f)); } }
protected void draw(Digraph result, Nfa<STATE> nfa) { for (STATE s : new NfaUtil().collect(nfa)) { result.add(create(result, nfa, s)); for (STATE f : nfa.getFollowers(s)) result.add(create(result, nfa, s, f)); } }
protected void draw(Digraph result, Pda<STATE, STACKITEM> pda) { for (STATE s : new NfaUtil().collect(pda)) { result.add(create(result, pda, s)); for (STATE f : pda.getFollowers(s)) result.add(create(result, pda, s, f)); } }
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; }
public Nfa<ISemState> getNFA(EObject context, EClass type) { Pair<EObject, EClass> key = Tuples.create(context, type); Nfa<ISemState> nfa = resultCache.get(key); if (nfa != null) return nfa; NfaUtil util = new NfaUtil(); SynAbsorberNfaAdapter synNfa = new SynAbsorberNfaAdapter(pdaProvider.getPDA(context, type)); // System.out.println(new NfaFormatter().format(synNfa)); Map<ISynAbsorberState, Integer> distanceMap = util.distanceToFinalStateMap(synNfa); nfa = util.create(util.sort(synNfa, distanceMap), new SemStateFactory()); // util.sortInplace(nfa, distanceMap); if (type != null) initContentValidationNeeded(type, nfa); initRemainingFeatures(nfa.getStop(), util.inverse(nfa), Sets.<ISemState> newHashSet()); initOrderIDs(nfa); // System.out.println(new NfaFormatter().format(nfa)); resultCache.put(key, nfa); return nfa; }
public AbstractElementAlias getShortSyntax() { Nfa<ISynState> path = new NfaUtil().filter(getPathToTarget(), new Filter()); return new NfaToProduction().nfaToGrammar(path, new GetGrammarElement(), new GrammarAliasFactory()); }