added arbitrary expression inversion, lookforward, and syntax for lookback
[sbp.git] / src / edu / berkeley / sbp / misc / CharToken.java
index 93ae7bb..143c708 100644 (file)
@@ -15,7 +15,9 @@ public class CharToken implements Token, IntegerTopology.IntegerMappable {
 
     public static class CharRange extends Atom<CharToken> {
         private String esc(char c) { return StringUtil.escapify(c+"", "[]-~\\\"\'"); }
-        public CharRange(Topology<CharToken> t) { super(t); }
+        private Topology<CharToken> t;
+        public CharRange(Topology<CharToken> t) { this.t = t; }
+        public Topology<CharToken> top() { return t; }
         public String toString() {
             StringBuffer sb = new StringBuffer();
             sb.append('[');
@@ -50,8 +52,10 @@ public class CharToken implements Token, IntegerTopology.IntegerMappable {
         return new CharRange(new IntegerTopology<CharToken>(new Range.Set(new Range((int)start, (int)end)).complement().intersect(all)));
     }
 
-    public static final Atom leftBrace  = new Atom(new IntegerTopology<CharToken>(-3)) { public String toString() { return "{"; } };
-    public static final Atom rightBrace = new Atom(new IntegerTopology<CharToken>(-4)) { public String toString() { return "}"; } };
+    public static CharToken left(int row, int col) { return new CharToken((char)9998, 0, 0) { public String toString() { return "{"; } }; }
+    public static CharToken right(int row, int col) { return new CharToken((char)9999, 0, 0) { public String toString() { return "}"; } }; }
+    public static final Atom leftBrace  = new CharRange(new IntegerTopology<CharToken>(9998)) { public String toString() { return "{"; } };
+    public static final Atom rightBrace = new CharRange(new IntegerTopology<CharToken>(9999)) { public String toString() { return "}"; } };
 
     private static final Range.Set all = new Range.Set(new Range(0, Character.MAX_VALUE));
     public  static final Atom      any = new CharRange(new IntegerTopology<CharToken>(all));
@@ -61,7 +65,7 @@ public class CharToken implements Token, IntegerTopology.IntegerMappable {
 
     /** returns an element which exactly matches the string given */
     public static Element string(String s) {
-        if (s.length() == 0) return MetaGrammar.epsilon;
+        if (s.length() == 0) return Union.epsilon;
         final String escapified = "\""+StringUtil.escapify(s, "\"\r\n\\")+"\"";
         Element ret;
         if (s.length() == 1) {
@@ -89,7 +93,7 @@ public class CharToken implements Token, IntegerTopology.IntegerMappable {
 
     public final char c;
     public final Location location;
-    CharToken(char c, int line, int col)   { this(c, new CartesianLocation(line, col)); }
+    public CharToken(char c, int line, int col)   { this(c, new CartesianLocation(line, col)); }
     private CharToken(char c, Location loc)        { this.c = c; this.location = loc; }
     public String result()                         { return c+""; }
     public Location getLocation()                  { return location; }