checkpoint
[sbp.git] / src / edu / berkeley / sbp / misc / CartesianInput.java
1 package edu.berkeley.sbp.misc;
2 import java.io.*;
3 import java.util.*;
4 import java.lang.reflect.*;
5 import java.lang.ref.*;
6 import edu.berkeley.sbp.*;
7 import edu.berkeley.sbp.Input.Location;
8 import edu.berkeley.sbp.util.*;
9
10 public abstract class CartesianInput<Token> implements Input<Token> {
11
12     public abstract Token   next() throws IOException;
13     public abstract boolean isCR();
14
15     long then = 0;
16     private CartesianLocation location = new CartesianLocation(1, 0);
17     public  Input.Location    getLocation() { return location; }
18
19     public Token next(int numstates, int resets, int waits) throws IOException {
20         int line  = location.line;
21         int col   = location.col;
22         Token t = next();
23         if (t==null) return null;
24         String s = "  line "+line+", col " + col;
25         while(s.length() < 20) s += " ";
26         s += "[ambiguity level: " + (numstates-1) + "] [resets: " + resets + "] [waits: " + waits + "]";
27         long now = System.currentTimeMillis();
28         if (now-then > 10) {
29             then = now;
30             System.out.print(s + "                                \r");
31         }
32         if (isCR()) { 
33             line++;
34             col = 1;
35         } else {
36             col++;
37         }
38         location = new CartesianLocation(line, col);
39         return t;
40     }
41 }