+ CharToken waitingBrace = null;
+ public CharToken nextc(int numstates, int resets) throws IOException {
+ char c;
+ if (waitingBrace != null) {
+ CharToken ret = waitingBrace;
+ waitingBrace = null;
+ return ret;
+ }
+ if (waiting) {
+ waiting = false;
+ c = waitingChar;
+ } else {
+ int i = br.read();
+ if (i==-1) {
+ if (istack.size() > 1) {
+ istack.remove(istack.size()-1);
+ return CharToken.right;
+ }
+ return null;
+ }
+ c = (char)i;
+ }
+ if (c=='\n') { _row++; _col=0; }
+ else _col++;
+ if (indenting) {
+ if (c==' ') { indentation++; return done(c); }
+ if (c=='\n') { indentation = 0; if (blank) return nextc(numstates, resets); blank = true; waiting = true; waitingChar='\n'; return new CharToken('\n'); }
+ int last = istack.size()==0 ? -1 : istack.get(istack.size()-1);
+ if (indentation==last) {
+ if (blank) {
+ indenting = false;
+ waitingChar = c;
+ waiting = true;
+ waitingBrace = CharToken.left;
+ return CharToken.right;
+ //return nextc(numstates);
+ }
+ blank = false;
+ indenting = false;
+ return done(c);
+ }
+ blank = false;
+ waitingChar = c;
+ waiting = true;
+ if (indentation > last) {
+ indenting = false;
+ istack.add(indentation);
+ //System.out.print("\033[31m+"+indentation+"+\033[0m");
+ return CharToken.left;
+ } else /*if (indentation < last)*/ {
+ istack.remove(istack.size()-1);
+ //System.out.print("\033[31m-"+last+"-\033[0m");
+ blank = true;
+ return CharToken.right;
+ }
+ } else {
+ blank = false;
+ if (c=='\n') { indenting=true; indentation = 0; }
+ return done(c);
+ }