+ 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 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;
+ }
+ 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");
+ }
+ }