checkpoint
authoradam <adam@megacz.com>
Thu, 14 Sep 2006 17:27:42 +0000 (13:27 -0400)
committeradam <adam@megacz.com>
Thu, 14 Sep 2006 17:27:42 +0000 (13:27 -0400)
darcs-hash:20060914172742-5007d-038c7d0cab6d86b285ec6a9df40f185fb87eb241.gz

src/edu/berkeley/sbp/chr/CharInput.java

index 10150d5..95609bc 100644 (file)
@@ -82,8 +82,6 @@ public class CharInput extends Cartesian.Input<Character> {
 
     int indentation = -1;
     int lastIndentation = 0;
-    int queuedIndentation = 0;
-    char queuedCharacter = ' ';
     int delta = 0;
 
     public boolean   isCR() { return cr; }
@@ -102,25 +100,6 @@ public class CharInput extends Cartesian.Input<Character> {
 
         cr = false;
 
-        if (queuedIndentation < 0) {
-            queuedIndentation++;
-            return CharAtom.right;
-        }
-        if (queuedSpaces > 0) {
-            queuedSpaces--;
-            return ' ';
-        }
-        if (queuedIndentation > 0) {
-            queuedIndentation--;
-            return CharAtom.left;
-        }
-
-        if (queuedCharacter != ' ') {
-            char ret = queuedCharacter;
-            queuedCharacter = ' ';
-            return ret;
-        }
-
         int i = r.read();
         if (i==-1) {
             /*System.err.print("\r...done       \r"); */
@@ -138,14 +117,27 @@ public class CharInput extends Cartesian.Input<Character> {
         cr = c=='\n';
 
         if (indent)
-            if (cr) {
-                indentation = 0;
-            } else if (c==' ' && indentation >= 0) {
-                indentation++;
-            } else if (indentation >= 0) {
-                //System.err.println("\r                   \rindent: " + (indentation - lastIndentation));
-                redent(indentation - lastIndentation);
-                r.unread(c);
+            if (cr && ignore) {
+                ignore = false;
+            } else if (cr) {
+                while(true) {
+                    indentation = 0;
+                    do { i = r.read(); if (i==' ') indentation++; } while (i==' ');
+                    if (i=='\n') { /* FIXME */ continue; }
+                    if (i==-1) { /* FIXME */ }
+                     if (indentation - lastIndentation > 0) {
+                        r.unread('\n');
+                        for(int j=0; j<indentation; j++) r.unread(' ');
+                        redent(indentation - lastIndentation);
+                    } else {
+                        redent(indentation - lastIndentation);
+                        r.unread('\n');
+                        for(int j=0; j<indentation; j++) r.unread(' ');
+                    }
+                    if (i != -1) r.unread((char)i);
+                    ignore = true;
+                    break;
+                }
                 lastIndentation = indentation;
                 indentation = -1;
                 return __next();
@@ -154,13 +146,13 @@ public class CharInput extends Cartesian.Input<Character> {
         return c;
     }
 
+    private boolean ignore = false;
+
     private void redent(int i) {
         if (i<0) { r.unread(CharAtom.right); redent(i+1); return; }
         if (i>0) { r.unread(CharAtom.left); redent(i-1); return; }
     }
 
-    int queuedSpaces = 0;
-
     public String showRegion(Region<Character> rc) {
         if (cache == null) return null;
         Cartesian.Region r = (Cartesian.Region)rc;