protected String getCardinality(Production<ELEMENT, TOKEN> adapter, ELEMENT ele) { return adapter.isMany(ele) ? adapter.isOptional(ele) ? "*" : "+" : adapter.isOptional(ele) ? "?" : null; }
protected String getCardinality(Production<ELEMENT, TOKEN> adapter, ELEMENT ele) { return adapter.isMany(ele) ? adapter.isOptional(ele) ? "*" : "+" : adapter.isOptional(ele) ? "?" : null; }
public Iterable<E> getStarts(E root) { if (root == null) throw new NullPointerException(); Set<E> outgoing = Sets.newLinkedHashSet(); if (filter(root)) { outgoing.add(root); if (production.isOptional(root)) outgoing.add(null); } else collectChildren(root, outgoing, Sets.<E> newHashSet()); return outgoing; }
@Override public Iterable<E> getStarts(E root) { if (root == null) throw new NullPointerException(); Set<E> outgoing = Sets.newLinkedHashSet(); if (filter(root)) { outgoing.add(root); if (production.isOptional(root)) outgoing.add(null); } else collectChildren(root, outgoing, Sets.<E> newHashSet()); return outgoing; }
protected void collectChildrenSequence(E element, Iterable<E> sequentialChildren, Set<E> result, Set<E> visited) { boolean reachedEnd = true; for (E child : orderedIterable(sequentialChildren)) { collectElement(child, result, visited); if (!production.isOptional(child)) { reachedEnd = false; break; } } if (reachedEnd || production.isOptional(element)) collectByParent(element, result, visited); }
protected void collectChildrenAlternative(E element, Iterable<E> alternativeChildren, Set<E> result, Set<E> visited) { boolean optional = production.isOptional(element); for (E child : orderedIterable(alternativeChildren)) { optional |= production.isOptional(child); collectElement(child, result, visited); } if (optional) collectByParent(element, result, visited); }
protected void collectChildrenAlternative(E element, Iterable<E> alternativeChildren, Set<E> result, Set<E> visited) { boolean optional = production.isOptional(element); for (E child : orderedIterable(alternativeChildren)) { optional |= production.isOptional(child); collectElement(child, result, visited); } if (optional) collectByParent(element, result, visited); }
protected void collectChildrenSequence(E element, Iterable<E> sequentialChildren, Set<E> result, Set<E> visited) { boolean reachedEnd = true; for (E child : orderedIterable(sequentialChildren)) { collectElement(child, result, visited); if (!production.isOptional(child)) { reachedEnd = false; break; } } if (reachedEnd || production.isOptional(element)) collectByParent(element, result, visited); }
protected void collectChildrenUnorderedAlt(E element, Iterable<E> alternativeChildren, Set<E> result, Set<E> visited) { boolean hasMandatory = false; for (E child : orderedIterable(alternativeChildren)) { hasMandatory |= !production.isOptional(child); collectElement(child, result, visited); } if (!hasMandatory || production.isOptional(element)) collectByParent(element, result, visited); }
protected void collectChildrenUnorderedAlt(E element, Iterable<E> alternativeChildren, Set<E> result, Set<E> visited) { boolean hasMandatory = false; for (E child : orderedIterable(alternativeChildren)) { hasMandatory |= !production.isOptional(child); collectElement(child, result, visited); } if (!hasMandatory || production.isOptional(element)) collectByParent(element, result, visited); }
protected void collectByParentSequence(E element, E container, Iterable<E> children, Set<E> result, Set<E> visited) { List<E> sequentialChildren = orderedList(children); int i = sequentialChildren.indexOf(element) + 1; while (i < sequentialChildren.size()) { E next = sequentialChildren.get(i); collectElement(next, result, visited); if (production.isOptional(next)) i++; else break; } if (i >= sequentialChildren.size()) { if (production.isMany(container)) collectElement(container, result, visited); collectByParent(container, result, visited); } }
protected void collectByParentSequence(E element, E container, Iterable<E> children, Set<E> result, Set<E> visited) { List<E> sequentialChildren = orderedList(children); int i = sequentialChildren.indexOf(element) + 1; while (i < sequentialChildren.size()) { E next = sequentialChildren.get(i); collectElement(next, result, visited); if (production.isOptional(next)) i++; else break; } if (i >= sequentialChildren.size()) { if (production.isMany(container)) collectElement(container, result, visited); collectByParent(container, result, visited); } }
public <S, D, T> D clone(Production<S, T> production, S ele, ProductionFactory<D, T> factory) { boolean many = production.isMany(ele); boolean optional = production.isOptional(ele); T token = production.getToken(ele); if (token != null) return factory.createForToken(many, optional, token); Iterable<S> alternative = production.getAlternativeChildren(ele); if (alternative != null) return factory.createForAlternativeChildren(many, optional, clone(production, alternative, factory)); Iterable<S> group = production.getSequentialChildren(ele); if (group != null) return factory.createForSequentialChildren(many, optional, clone(production, group, factory)); Iterable<S> unorderedgroup = production.getUnorderedChildren(ele); if (unorderedgroup != null) return factory.createForUnordertedChildren(many, optional, clone(production, unorderedgroup, factory)); return factory.createForToken(many, optional, null); }
public <S, D, T> D clone(Production<S, T> production, S ele, ProductionFactory<D, T> factory) { boolean many = production.isMany(ele); boolean optional = production.isOptional(ele); T token = production.getToken(ele); if (token != null) return factory.createForToken(many, optional, token); Iterable<S> alternative = production.getAlternativeChildren(ele); if (alternative != null) return factory.createForAlternativeChildren(many, optional, clone(production, alternative, factory)); Iterable<S> group = production.getSequentialChildren(ele); if (group != null) return factory.createForSequentialChildren(many, optional, clone(production, group, factory)); Iterable<S> unorderedgroup = production.getUnorderedChildren(ele); if (unorderedgroup != null) return factory.createForUnordertedChildren(many, optional, clone(production, unorderedgroup, factory)); return factory.createForToken(many, optional, null); }