import edu.berkeley.sbp.*;
import edu.berkeley.sbp.*;
-/** <font color=green>an element which matches exactly one input token</font> */
+/**
+ * <font color=green>an element which matches some set of one-token-long input strings</font>.
+ *
+ * This class is a topology over itself so that Atoms can be
+ * intersected and unioned with each other to result in other
+ * Atom<T>'s (rather than raw Topology<T>'s, which are not Elements).
+ * If you want the latter, use the getTokenTopology() method.
+ */
public abstract class Atom<T> extends Element implements Topology<Atom<T>> {
- public abstract Topology<T> underlying();
- public abstract String toString();
- public StringBuffer toString(StringBuffer sb) { sb.append(this); return sb; }
+ /** the set (topology) of tokens that can match this element */
+ public abstract Topology<T> getTokenTopology();
+ public abstract StringBuffer toString(StringBuffer sb);
}
// if the element following this position is an atom, copy the corresponding
// set of rows out of the "master" goto table and into this state's shift table
if (p.element() != null && p.element() instanceof Atom)
- state.shifts.addAll(state.gotoSetTerminals.subset(((Atom)p.element()).underlying()));
+ state.shifts.addAll(state.gotoSetTerminals.subset(((Atom)p.element()).getTokenTopology()));
}
if (top instanceof IntegerTopology)
for(State<Tok> state : all_states.values()) {
Atom a = (Atom)position.element();
HashSet<Position> hp = new HashSet<Position>();
reachable(position.next(), hp);
- bag0.addAll(a.underlying(), hp);
+ bag0.addAll(a.getTokenTopology(), hp);
}
// Step 1b: for each _minimal, contiguous_ set of characters having an identical next-position
public WalkTokenSet(Topology<Tok> cs) { this.cs = cs; }
public WalkTokenSet(Topology<Tok> cs, Cache c) { super(c); this.cs = cs; }
public Topology<Tok> bottom(Element e) { return cs; }
- public Topology<Tok> walkAtom(Atom r) { cs = cs.union(r.underlying()); return cs; }
+ public Topology<Tok> walkAtom(Atom r) { cs = cs.union(r.getTokenTopology()); return cs; }
}
static class First<Tok extends Input> extends WalkTokenSet<Tok> {
if (e instanceof Sequence) {
Sequence s = (Sequence)e;
- if (s.follow() != null) cs = cs.intersect(s.follow().underlying());
+ if (s.follow() != null) cs = cs.intersect(s.follow().getTokenTopology());
}
if (c != null && e==me) {
public class CharAtom extends Atom<Character> {
+ public StringBuffer toString(StringBuffer sb) { sb.append(this); return sb; }
+
public CharAtom() { this(new CharTopology()); }
public CharAtom(char a) { this(a,a); }
public CharAtom(char a, char b) { this(new CharTopology(a, b)); }
public static final Atom braces = new CharAtom(left,right) { public String toString() { return "[{}]"; } };
public static Atom set(Range.Set r) { return new CharAtom(new CharTopology(r)); }
-
public String toString() { return t.toString(); }
/** returns an element which exactly matches the string given */
public Topology<Atom<Character>> unwrap() { return this; }
public Topology<Atom<Character>> empty() { return new CharAtom(); }
- public Topology<Character> underlying() { return top(); }
+ public Topology<Character> getTokenTopology() { return top(); }
public boolean contains(Atom<Character> v) { return top().containsAll(((CharAtom)v).top()); }
public boolean disjoint(Topology<Atom<Character>> t) { return top().disjoint(((CharAtom)t).top()); }