1 package edu.berkeley.sbp.misc;
4 import java.lang.reflect.*;
5 import java.lang.ref.*;
6 import edu.berkeley.sbp.*;
7 import edu.berkeley.sbp.Token.Location;
8 import edu.berkeley.sbp.util.*;
10 public class CharToStringParser extends Parser<Character,String> {
11 public Forest<String> parse(InputStream is) throws IOException, ParseFailed {
12 return super.parse(new Stream(is));
14 public Forest<String> parse(Reader r) throws IOException, ParseFailed {
15 return super.parse(new Stream(r));
18 public CharToStringParser(Union u) {
19 super(u, new IntegerTopology<Character>(CharToken.c2i));
20 pt.optimize(CharToken.c2i);
22 public Forest<String> shiftToken(Character ct, Location loc) {
23 return Forest.create(loc, ct.toString(), null, false, false);
26 private static class Stream extends CartesianInput<Character> {
27 private final Reader r;
29 public Stream(String s) { this(new StringReader(s)); }
30 public Stream(Reader r) { this(r, null); }
31 public Stream(Reader r, String s) { this.r = r; }
32 public Stream(InputStream i) { this(i, null); }
33 public Stream(InputStream i, String s) { this(new InputStreamReader(i), s); }
36 public boolean isCR() { return cr; }
37 public Character next() throws IOException {
40 if (i==-1) return null;