public Pattern fix() { fixIdentities(null); fixRepeatingArguments(); return this; }
/** * Make pattern-tree tips point to same object if they are equal. */ private void fixIdentities(List<Pattern> uniq) { // >>> if not hasattr(self, 'children') if (!(this instanceof BranchPattern)) { return; } if (uniq == null) { uniq = list(set(flat())); } final List<Pattern> children = ((BranchPattern) this).getChildren(); for (int i = 0; i < children.size(); i++) { final Pattern child = children.get(i); if (!(child instanceof BranchPattern)) { assert uniq.contains(child); children.set(i, uniq.get(uniq.indexOf(child))); } else { child.fixIdentities(uniq); } } }
protected MatchResult match(final List<LeafPattern> left) { return match(left, null); }
@Override protected final List<Pattern> flat(final Class<?>... types) { if (in(getClass(), types)) { return list((Pattern) this); } // >>> return sum([child.flat(*types) for child in self.children], []) { final List<Pattern> result = list(); for (final Pattern child : children) { result.addAll(child.flat(types)); } return result; } }
for (final Pattern child : transform(this).getChildren()) { either.add(list(((Required) child).getChildren()));
@Override protected final List<Pattern> flat(final Class<?>... types) { if (in(getClass(), types)) { return list((Pattern) this); } // >>> return sum([child.flat(*types) for child in self.children], []) { final List<Pattern> result = list(); for (final Pattern child : children) { result.addAll(child.flat(types)); } return result; } }
for (final Pattern child : transform(this).getChildren()) { either.add(list(((Required) child).getChildren()));
protected MatchResult match(final List<LeafPattern> left) { return match(left, null); }
public Pattern fix() { fixIdentities(null); fixRepeatingArguments(); return this; }
/** * Make pattern-tree tips point to same object if they are equal. */ private void fixIdentities(List<Pattern> uniq) { // >>> if not hasattr(self, 'children') if (!(this instanceof BranchPattern)) { return; } if (uniq == null) { uniq = list(set(flat())); } final List<Pattern> children = ((BranchPattern) this).getChildren(); for (int i = 0; i < children.size(); i++) { final Pattern child = children.get(i); if (!(child instanceof BranchPattern)) { assert uniq.contains(child); children.set(i, uniq.get(uniq.indexOf(child))); } else { child.fixIdentities(uniq); } } }
final MatchResult m = pattern.match(left, collected); if (m.matched()) { outcomes.add(m);
final MatchResult m = pattern.match(left, collected); if (m.matched()) { outcomes.add(m);
@Override protected MatchResult match(List<LeafPattern> left, List<LeafPattern> collected) { if (collected == null) { collected = list(); } for (final Pattern pattern : getChildren()) { final MatchResult u = pattern.match(left, collected); left = u.getLeft(); collected = u.getCollected(); } return new MatchResult(true, left, collected); } }
@Override protected MatchResult match(List<LeafPattern> left, List<LeafPattern> collected) { if (collected == null) { collected = list(); } for (final Pattern pattern : getChildren()) { final MatchResult u = pattern.match(left, collected); left = u.getLeft(); collected = u.getCollected(); } return new MatchResult(true, left, collected); } }
final MatchResult m = getChildren().get(0).match(l, c);
final MatchResult m = getChildren().get(0).match(l, c);
@Override protected MatchResult match(final List<LeafPattern> left, List<LeafPattern> collected) { if (collected == null) { collected = list(); } List<LeafPattern> l = left; List<LeafPattern> c = collected; for (final Pattern pattern : getChildren()) { final MatchResult m = pattern.match(l, c); l = m.getLeft(); c = m.getCollected(); if (!m.matched()) { return new MatchResult(false, left, collected); } } return new MatchResult(true, l, c); } }
@Override protected MatchResult match(final List<LeafPattern> left, List<LeafPattern> collected) { if (collected == null) { collected = list(); } List<LeafPattern> l = left; List<LeafPattern> c = collected; for (final Pattern pattern : getChildren()) { final MatchResult m = pattern.match(l, c); l = m.getLeft(); c = m.getCollected(); if (!m.matched()) { return new MatchResult(false, left, collected); } } return new MatchResult(true, l, c); } }