+package edu.berkeley.sbp.misc;
+import java.io.*;
+import java.util.*;
+import java.lang.reflect.*;
+import java.lang.ref.*;
+import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.util.*;
+import edu.berkeley.sbp.*;
+
+/** an implementation of Token for streams of Java <tt>char</tt> values */
+public class StringToken implements Token {
+
+ public static final StringToken left = new StringToken(null, null) { public boolean equals(Object o) { return this==o; } };
+ public static final StringToken right = new StringToken(null, null) { public boolean equals(Object o) { return this==o; } };
+
+ public static final Atom leftBrace = new Atom(new DiscreteTopology<StringToken>(left)) { public String toString() { return "{"; } };
+ public static final Atom rightBrace = new Atom(new DiscreteTopology<StringToken>(right)) { public String toString() { return "}"; } };
+
+ private static class StringAtom extends Atom {
+ private String s;
+ public StringAtom(String s) { super(new DiscreteTopology<StringToken>(new StringToken(s, null))); this.s = s; }
+ public String toString() { return "[atom \""+s+"\"]"; }
+ }
+
+ /** returns an element which exactly matches the string given */
+ public static Element string(String s) {
+ return new StringAtom(s);
+ }
+
+ public static Topology<StringToken> top() { return new DiscreteTopology<StringToken>(); }
+
+ public final String s;
+ public final Location location;
+ private StringToken(String s, Location loc) { this.s = s; this.location = loc; }
+ public String result() { return s; }
+ public Location getLocation() { return location; }
+ public String toString() { return "\'"+StringUtil.escapify(s)+"\'"; }
+
+ public boolean equals(Object o) { return o!=null && o instanceof StringToken && s.equals(((StringToken)o).s); }
+ public int hashCode() { return s==null ? 0 : s.hashCode(); }
+}