import edu.berkeley.sbp.util.*;
/** a token of input -- note that this represents an <i>actual input token</i> rather than an <tt>Element</tt> which <i>matches</i> a token */
-public interface Input {
+public interface Input<Tok> {
- /** this is declared abstract as a way of forcing subclasses to provide a thoughtful implementation */
- public abstract String toString();
-
- /** a sequence of input tokens; returns null when EOF is reached */
- public static interface Stream<Tok> {
- public Tok next(int numstates, int resets, int waits) throws IOException;
- public abstract Location getLocation();
- }
+ public Tok next(int numstates, int resets, int waits) throws IOException;
+ public abstract Location getLocation();
/** a location *between tokens* in the input stream */
public static interface Location {
public abstract Forest<Result> shiftToken(Tok t, Input.Location loc);
/** parse <tt>input</tt>, using the table <tt>pt</tt> to drive the parser */
- public Forest<Result> parse(Input.Stream<Tok> input) throws IOException, ParseFailed {
+ public Forest<Result> parse(Input<Tok> input) throws IOException, ParseFailed {
GSS gss = new GSS();
Input.Location loc = input.getLocation();
GSS.Phase current = gss.new Phase<Tok>(null, this, null, input.next(1, 0, 0), loc, null);
import edu.berkeley.sbp.Input.Location;
import edu.berkeley.sbp.util.*;
-public abstract class CartesianInput<Tok> implements Input.Stream<Tok> {
+public abstract class CartesianInput<Tok> implements Input<Tok> {
private int line = 1;
private int col = 0;
private boolean strings;
private Element set(Range.Set r) { if (strings) throw new Error(); return CharRange.set(r); }
- private Element string(String s) { return strings ? StringToken.string(s) : CharRange.string(s); }
- private Atom leftBrace() { return strings ? StringToken.leftBrace : CharRange.leftBrace; }
- private Atom rightBrace() { return strings ? StringToken.rightBrace : CharRange.rightBrace; }
+ private Element string(String s) { return strings ? StringInput.string(s) : CharRange.string(s); }
+ private Atom leftBrace() { return strings ? StringInput.leftBrace : CharRange.leftBrace; }
+ private Atom rightBrace() { return strings ? StringInput.rightBrace : CharRange.rightBrace; }
public MetaGrammar() { this("s", false); }
public MetaGrammar(String s) { this(s, false); }
import java.lang.reflect.*;
import java.lang.ref.*;
import edu.berkeley.sbp.*;
-import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.Input.Location;
import edu.berkeley.sbp.util.*;
-import edu.berkeley.sbp.*;
/** an implementation of Input for streams of Java <tt>char</tt> values */
-public class StringToken implements Input {
+public class StringInput {
- public static final StringToken left = new StringToken(null, null) { public boolean equals(Object o) { return this==o; } };
- public static final StringToken right = new StringToken(null, null) { public boolean equals(Object o) { return this==o; } };
+ public static final StringInput left = new StringInput(null, null) { public boolean equals(Object o) { return this==o; } };
+ public static final StringInput right = new StringInput(null, null) { public boolean equals(Object o) { return this==o; } };
- public static final Atom leftBrace = new StringAtom(new DiscreteTopology<StringToken>(left)) { public String toString() { return "{"; } };
- public static final Atom rightBrace = new StringAtom(new DiscreteTopology<StringToken>(right)) { public String toString() { return "}"; } };
+ public static final Atom leftBrace = new StringAtom(new DiscreteTopology<StringInput>(left)) { public String toString() { return "{"; } };
+ public static final Atom rightBrace = new StringAtom(new DiscreteTopology<StringInput>(right)) { public String toString() { return "}"; } };
private static class StringAtom extends Atom {
private String s;
private Topology t;
- public StringAtom(String s) { this.t = new DiscreteTopology<StringToken>(new StringToken(s, null)); this.s = s; }
- public StringAtom(Topology<StringToken> t) { this.t = t; }
+ public StringAtom(String s) { this.t = new DiscreteTopology<StringInput>(new StringInput(s, null)); this.s = s; }
+ public StringAtom(Topology<StringInput> t) { this.t = t; }
public String toString() { return "[atom \""+s+"\"]"; }
public Topology top() { return t; }
}
return new StringAtom(s);
}
- public static Topology<StringToken> top() { return new DiscreteTopology<StringToken>(); }
+ public static Topology<StringInput> top() { return new DiscreteTopology<StringInput>(); }
public final String s;
public final Location location;
- private StringToken(String s, Location loc) { this.s = s; this.location = loc; }
+ private StringInput(String s, Location loc) { this.s = s; this.location = loc; }
public String result() { return s; }
public Location getLocation() { return location; }
public String toString() { return "\'"+StringUtil.escapify(s)+"\'"; }
- public boolean equals(Object o) { return o!=null && o instanceof StringToken && s.equals(((StringToken)o).s); }
+ public boolean equals(Object o) { return o!=null && o instanceof StringInput && s.equals(((StringInput)o).s); }
public int hashCode() { return s==null ? 0 : s.hashCode(); }
}
* experimentation with the TIB spec. Once the spec is finalized it
* should probably be rewritten.
*/
-public class Tib implements Input.Stream<Character> {
+public class Tib implements Input<Character> {
public Tib(String s) throws IOException { this(new StringReader(s)); }
public Tib(Reader r) throws IOException { this(new BufferedReader(r)); }