checkpoint
[sbp.git] / src / edu / berkeley / sbp / chr / CharParser.java
index db235cd..c901388 100644 (file)
@@ -9,39 +9,20 @@ import edu.berkeley.sbp.misc.*;
 import edu.berkeley.sbp.Input.Location;
 
 public class CharParser extends Parser<Character,String> {
-    public Forest<String> parse(InputStream is) throws IOException, ParseFailed {
-        return super.parse(new Stream(is));
-    }
-    public Forest<String> parse(Reader r) throws IOException, ParseFailed {
-        return super.parse(new Stream(r));
-    }
 
-    public CharParser(Union u) {
-        super(u, new CharTopology());
-        pt.optimize(new CharTopology());
-    }
-    public Forest<String> shiftToken(Character ct, Location loc) {
-        return Forest.create(loc, ct.toString(), null, false, false);
-    }
+    public Forest<String> parse(InputStream is) throws IOException, ParseFailed { return super.parse(new CharInput(is)); }
+    public Forest<String> parse(Reader r)       throws IOException, ParseFailed { return super.parse(new CharInput(r)); }
+    public Forest<String> parse(String s)       throws IOException, ParseFailed { return parse(new StringReader(s)); }
+
+    public CharParser(Union u) { super(u, new CharTopology()); }
 
-    private static class Stream extends CartesianInput<Character> {
-        private final Reader r;
-        
-        public Stream(String s)                { this(new StringReader(s)); }
-        public Stream(Reader r)                { this(r, null); }
-        public Stream(Reader r,      String s) { this.r = r; }
-        public Stream(InputStream i)           { this(i, null); }
-        public Stream(InputStream i, String s) { this(new InputStreamReader(i), s); }
+    private Location oldloc;
 
-        boolean cr = false;
-        public boolean   isCR() { return cr; }
-        public Character next() throws IOException {
-            cr = false;
-            int i = r.read();
-            if (i==-1) return null;
-            char c = (char)i;
-            cr = c=='\n';
-            return c;
-        }
+    public Forest<String> shiftToken(Character ct, Location newloc) {
+        if (oldloc==null) oldloc = newloc;
+        Forest<String> ret = Forest.create(oldloc.createRegion(newloc), ct.toString(), null);
+        oldloc = newloc;
+        return ret;
     }
+
 }