cleanups, reorg, and commenting
[sbp.git] / src / edu / berkeley / sbp / chr / CharParser.java
index db235cd..7b6d560 100644 (file)
@@ -1,47 +1,21 @@
+// Copyright 2006 all rights reserved; see LICENSE file for BSD-style license
+
 package edu.berkeley.sbp.chr;
 import java.io.*;
 import java.util.*;
 package edu.berkeley.sbp.chr;
 import java.io.*;
 import java.util.*;
-import java.lang.reflect.*;
-import java.lang.ref.*;
 import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.util.*;
-import edu.berkeley.sbp.misc.*;
-import edu.berkeley.sbp.Input.Location;
 
 public class CharParser extends Parser<Character,String> {
 
 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); }
 
 
-    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); }
+    public Topology<Character> emptyTopology() { return new CharTopology(); }
+    public Forest<String> shiftToken(Character ct, Input.Region region) {
+        return Forest.create(region, ct.toString(), null); }
 
 
-        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;
-        }
-    }
 }
 }