checkpoint
[sbp.git] / src / edu / berkeley / sbp / misc / Cartesian.java
index 50ddbab..2c32553 100644 (file)
@@ -17,12 +17,13 @@ public class Cartesian {
         public abstract boolean isCR();
 
         long then = 0;
-        private Cartesian.Location location = new Cartesian.Location(0, 1);
+        private Cartesian.Location location = new Cartesian.Location();
         public  edu.berkeley.sbp.Input.Location    getLocation() { return location; }
 
         public Token next() throws IOException {
-            int line  = location.getRow();
-            int col   = location.getCol();
+            int line   = location.getRow();
+            int col    = location.getCol();
+           int scalar = location.getScalar();
             Token t = _next();
             if (t==null) return null;
             String s = "  line "+line+", col " + col;
@@ -39,19 +40,32 @@ public class Cartesian {
             } else {
                 col++;
             }
-            location = new Cartesian.Location(col, line);
+            location.next = new Cartesian.Location(col, line, scalar+1);
+            location.next.prev = location;
+            location = location.next;
             return t;
         }
+
+        public String showRegion(Input.Region<Token> region) {
+            return null;
+        }
     }
 
     /** an implementation of Location for a cartesian grid (row, col) */
     public static class Location<Tok> implements Input.Location<Tok>, Comparable<Input.Location> {
         protected final int row;
         protected final int col;
+        protected final int scalar;
+        Location<Tok> next = null;
+        Location<Tok> prev = null;
+        public Location<Tok> next() { return next; }
+        public Location<Tok> prev() { return prev; }
         public String toString() { return row+":"+col; }
         public int getCol() { return col; }
         public int getRow() { return row; }
-        public Location(int col, int row) { this.row = row; this.col = col; }
+        public int getScalar() { return scalar; }
+        public Location() { this(-1, 1, 0); }
+        public Location(int col, int row, int scalar) { this.row = row; this.col = col; this.scalar = scalar; }
         public int compareTo(Input.Location loc) throws ClassCastException {
             if (!(loc instanceof Cartesian.Location)) throw new ClassCastException(loc.getClass().getName());
             Location<Tok> c = (Location<Tok>)loc;
@@ -68,7 +82,10 @@ public class Cartesian {
     public static class Region<Tok> implements Input.Region<Tok> {
         public final Location<Tok> start;
         public final Location<Tok> end;
+        public Location<Tok> getStart() { return start; }
+        public Location<Tok> getEnd() { return end; }
         public String toString() {
+            if (start.row==end.row && start.col==end.col) return start+"";
             if (start.row==end.row) return start.row+":"+(start.col+"-"+end.col);
             return start+"-"+end;
         }