checkpoint
[sbp.git] / src / edu / berkeley / sbp / misc / Cartesian.java
index 676a4cf..23e5884 100644 (file)
@@ -59,5 +59,24 @@ public class Cartesian {
             if (col > c.col) return  1;
             return 0;
         }
+        public Input.Region<Tok> createRegion(Input.Location<Tok> loc) {
+            return new Region<Tok>(this, (Cartesian.Location<Tok>)loc); }
+    }
+
+    public static class Region<Tok> implements Input.Region<Tok> {
+        public final Location<Tok> start;
+        public final Location<Tok> end;
+        public String toString() {
+            if (start.row==end.row) return start.row+":"+(start.col+"-"+end.col);
+            return start+"-"+end;
+        }
+        public Region(Location<Tok> a, Location<Tok> b) {
+            switch(a.compareTo(b)) {
+                case -1:
+                case  0: start=a; end=b; return;
+                case  1: start=b; end=a; return;
+                default: throw new Error("impossible");
+            }
+        }
     }
 }