1 package edu.berkeley.sbp.chr;
4 import java.lang.reflect.*;
5 import java.lang.ref.*;
6 import edu.berkeley.sbp.*;
7 import edu.berkeley.sbp.util.*;
8 import edu.berkeley.sbp.misc.*;
9 import edu.berkeley.sbp.Input.Location;
11 public class CharParser extends Parser<Character,String> {
12 public Forest<String> parse(InputStream is) throws IOException, ParseFailed {
13 return super.parse(new Stream(is));
15 public Forest<String> parse(Reader r) throws IOException, ParseFailed {
16 return super.parse(new Stream(r));
19 public CharParser(Union u) {
20 super(u, new CharTopology());
21 pt.optimize(new CharTopology());
23 public Forest<String> shiftToken(Character ct, Location loc) {
24 return Forest.create(loc, ct.toString(), null, false, false);
27 private static class Stream extends CartesianInput<Character> {
28 private final Reader r;
30 public Stream(String s) { this(new StringReader(s)); }
31 public Stream(Reader r) { this(r, null); }
32 public Stream(Reader r, String s) { this.r = r; }
33 public Stream(InputStream i) { this(i, null); }
34 public Stream(InputStream i, String s) { this(new InputStreamReader(i), s); }
37 public boolean isCR() { return cr; }
38 public Character next() throws IOException {
41 if (i==-1) return null;