@SuppressWarnings("unchecked") public Collection<T> finish() { if (lastState != null) { List<IElementPattern> result = Lists.<IElementPattern> newArrayList(lastState.getAfterPatterns()); while (!ruleCallStack.isEmpty()) result.addAll(ruleCallStack.pop().getAfterPatterns()); // String file = lastState.getGrammarElement().eResource().getURI().lastSegment() + "3.pdf"; // try { // new ElementMatcherToDot().draw(this, file, "-T pdf"); // } catch (IOException e) { // e.printStackTrace(); // } lastState = null; return (Collection<T>) result; } else return Collections.emptyList(); }
@SuppressWarnings("unchecked") protected Collection<T> patternsForTwoStates(MatcherState first, MatcherState second) { Collection<IElementPattern> result = Sets.newHashSet(); if (first != null) { result.addAll(first.getAfterPatterns()); for (IBetweenElements between : first.getAfterBetweenElements()) if (getAllStates(between.matchBetween().getSecond()).contains(second)) result.add(between); for (IBetweenElements between : second.getBeforeBetweenElements()) if (getAllStates(between.matchBetween().getFirst()).contains(first)) result.add(between); } result.addAll(second.getBeforePatterns()); return (Collection<T>) result; } }
protected void installAfter(IAfterElement pattern) { Set<MatcherState> states = getAllStates(pattern.matchAfter()); AbstractRule rule = GrammarUtil.containingRule(pattern.matchAfter()); for (MatcherState state : states) { state.getAfterPatterns().add(pattern); for (MatcherTransition out : state.isParserRuleCall() ? state.getOutgoingAfterReturn() : state .getOutgoing()) if (pattern.matchAfter() == out.getLoopCenter() || !states.contains(out.getTarget())) out.addPattern(pattern); if (state.isEndState()) for (MatcherState caller : findRuleCallsTo(rule, Sets.<AbstractRule> newHashSet())) for (MatcherTransition afterReturn : caller.getOutgoingAfterReturn()) afterReturn.addPattern(state, pattern); } }