// Public //////////////////////////////////////////////////////////////////////////////
+ public static class CharToStringParser extends Parser<CharToken,String> {
+ public CharToStringParser(Union u) { super(u); }
+ public Topology<CharToken> top() { return new IntegerTopology<CharToken>(); }
+ public Forest<String> shiftedToken(CharToken ct, Token.Location loc) {
+ return Forest.create(loc, ct.result(), null, null, false, false);
+ }
+ }
+
public static class CharRange extends Atom<CharToken> {
private String esc(char c) { return StringUtil.escapify(c+"", "[]-~\\\"\'"); }
- public CharRange(Topology<CharToken> t) { super(t); }
+ private Topology<CharToken> t;
+ public CharRange(Topology<CharToken> t) { this.t = t; }
+ public Topology<CharToken> top() { return t; }
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append('[');
return new CharRange(new IntegerTopology<CharToken>(new Range.Set(new Range((int)start, (int)end)).complement().intersect(all)));
}
- public static CharToken left(int row, int col) { return new CharToken((char)9998, 0, 0) { public String toString() { return "{"; } }; }
- public static CharToken right(int row, int col) { return new CharToken((char)9999, 0, 0) { public String toString() { return "}"; } }; }
- public static final Atom leftBrace = new Atom(new IntegerTopology<CharToken>(9998)) { public String toString() { return "{"; } };
- public static final Atom rightBrace = new Atom(new IntegerTopology<CharToken>(9999)) { public String toString() { return "}"; } };
+ public static final Atom leftBrace = new CharRange(new IntegerTopology<CharToken>(9998)) { public String toString() { return "{"; } };
+ public static final Atom rightBrace = new CharRange(new IntegerTopology<CharToken>(9999)) { public String toString() { return "}"; } };
+ public static final CharToken left = new CharToken((char)9998);
+ public static final CharToken right = new CharToken((char)9999);
private static final Range.Set all = new Range.Set(new Range(0, Character.MAX_VALUE));
public static final Atom any = new CharRange(new IntegerTopology<CharToken>(all));
// Private //////////////////////////////////////////////////////////////////////////////
public final char c;
- public final Location location;
- public CharToken(char c, int line, int col) { this(c, new CartesianLocation(line, col)); }
- private CharToken(char c, Location loc) { this.c = c; this.location = loc; }
- public String result() { return c+""; }
- public Location getLocation() { return location; }
- public String toString() { return "\'"+StringUtil.escapify(c+"")+"\'"; }
+ public CharToken(char c) { this.c = c; }
+ public String result() { return c+""; }
+ public String toString() { return "\'"+StringUtil.escapify(c+"")+"\'"; }
//////////////////////////////////////////////////////////////////////////////////////////
// Statics //////////////////////////////////////////////////////////////////////////////
- static class CartesianLocation implements Location {
+ public static class CartesianLocation implements Location {
public final int line;
public final int col;
public String toString() { return line + ":" + col; }
public CartesianLocation(int line, int col) { this.line = line; this.col = col; }
- public String getContext() { return ""; }
}
/** an implementation of Token.Stream for sequences of characters */
}
long then = 0;
+ private Token.Location location = new LocWrap(1, 1);
+ public Token.Location getLocation() { return location; }
public Token next() throws IOException {
int i = r.read();
if (i==-1) return null;
char c = (char)i;
- Token ret = new CharToken(c, new LocWrap(line, col));
+ location = new LocWrap(line, col);
+ Token ret = new CharToken(c);
String s = line + "";
while(s.length() < 4) s = " " + s;
s = "line "+s+", col " + col;