checkpoint
authoradam <adam@megacz.com>
Sun, 15 Jan 2006 11:03:14 +0000 (06:03 -0500)
committeradam <adam@megacz.com>
Sun, 15 Jan 2006 11:03:14 +0000 (06:03 -0500)
darcs-hash:20060115110314-5007d-95cfa97478f0e08071641815931951ab4bec8109.gz

src/edu/berkeley/sbp/Input.java
src/edu/berkeley/sbp/Parser.java
src/edu/berkeley/sbp/misc/CartesianInput.java
src/edu/berkeley/sbp/misc/MetaGrammar.java
src/edu/berkeley/sbp/misc/StringInput.java [moved from src/edu/berkeley/sbp/misc/StringToken.java with 67% similarity]
src/edu/berkeley/sbp/tib/Tib.java

index b326468..d8374cd 100644 (file)
@@ -7,16 +7,10 @@ import edu.berkeley.sbp.*;
 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 {
index 87b5508..75f3ace 100644 (file)
@@ -18,7 +18,7 @@ public abstract class Parser<Tok, Result> {
     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);
index 200396e..4930173 100644 (file)
@@ -7,7 +7,7 @@ import edu.berkeley.sbp.*;
 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;
index 03f8f97..7f4120f 100644 (file)
@@ -40,9 +40,9 @@ public class MetaGrammar extends StringWalker {
     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); }
similarity index 67%
rename from src/edu/berkeley/sbp/misc/StringToken.java
rename to src/edu/berkeley/sbp/misc/StringInput.java
index b21e458..1f3d0d3 100644 (file)
@@ -4,24 +4,23 @@ import java.util.*;
 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; }
     }
@@ -31,15 +30,15 @@ public class StringToken implements Input {
         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(); }
 }
index 15c286a..6693600 100644 (file)
@@ -24,7 +24,7 @@ import java.io.*;
  *   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)); }