checkpoint
authoradam <adam@megacz.com>
Sun, 15 Jan 2006 10:59:30 +0000 (05:59 -0500)
committeradam <adam@megacz.com>
Sun, 15 Jan 2006 10:59:30 +0000 (05:59 -0500)
darcs-hash:20060115105930-5007d-6df5f9158f1d2637d73f600779fd7915ef75dbf3.gz

18 files changed:
src/edu/berkeley/sbp/Atom.java
src/edu/berkeley/sbp/Forest.java
src/edu/berkeley/sbp/GSS.java
src/edu/berkeley/sbp/Input.java [moved from src/edu/berkeley/sbp/Token.java with 97% similarity]
src/edu/berkeley/sbp/ParseFailed.java
src/edu/berkeley/sbp/Parser.java
src/edu/berkeley/sbp/Sequence.java
src/edu/berkeley/sbp/Tree.java
src/edu/berkeley/sbp/Walk.java
src/edu/berkeley/sbp/chr/CharParser.java [moved from src/edu/berkeley/sbp/misc/CharToStringParser.java with 87% similarity]
src/edu/berkeley/sbp/chr/CharRange.java [moved from src/edu/berkeley/sbp/misc/CharRange.java with 94% similarity]
src/edu/berkeley/sbp/chr/CharTopology.java [moved from src/edu/berkeley/sbp/misc/CharTopology.java with 95% similarity]
src/edu/berkeley/sbp/misc/CartesianInput.java
src/edu/berkeley/sbp/misc/MetaGrammar.java
src/edu/berkeley/sbp/misc/RegressionTests.java
src/edu/berkeley/sbp/misc/StringToken.java
src/edu/berkeley/sbp/tib/Tib.java
src/edu/berkeley/sbp/tib/TibDoc.java

index 03383ab..cb7a379 100644 (file)
@@ -31,28 +31,18 @@ public abstract class Atom<T> extends Element implements Topology<T> {
 
     // Subclasses //////////////////////////////////////////////////////////////////////////////
 
-    public static class Infer<T extends Token> extends Atom<T> {
+    public static class Infer<T extends Input> extends Atom<T> {
         private final Element e;
         public Infer(Element e) { this.e = e; }
         public Topology<T> top() { return (Topology<T>)e.toAtom(); }
         public String toString() { return e.toString(); /* FIXME should be toAtom() */ }
     }
     
-    public static class Invert<T extends Token> extends Atom<T> {
+    public static class Invert<T extends Input> extends Atom<T> {
         private final Atom<T> a;
         public Invert(Atom<T> a) { this.a = a; }
         public Topology<T> top() { return ((Topology<T>)a.top()).complement(); }
         public String toString() { return "~"+a; }
     }
-    
-    public static class Hack<T extends Token> extends Atom<T> {
-        private final Atom<T> a;
-        static final Topology leftright =
-            edu.berkeley.sbp.misc.CharRange.rightBrace.union(edu.berkeley.sbp.misc.CharRange.leftBrace);
-        public Hack(Atom<T> a) { this.a = a; }
-        public Topology<T> top() { return ((Topology<T>)a.top()).minus(leftright); }
-        public String toString() { return "~"+a; }
-    }
-    
 }
 
index 917fea5..e4572ec 100644 (file)
@@ -19,10 +19,10 @@ public abstract class Forest<T> {
     /** expand this forest into a set of trees */
     public abstract HashSet<Tree<T>>  expand(boolean toss);
 
-    static        <T> Forest<T> singleton(Token.Location loc)                       { return create(loc, null, new Forest[] { }, false, true); }
-    static        <T> Forest<T> singleton(Token.Location loc, Forest<T> body)       { return create(loc, null, new Forest[] { body },  false, true); }
-    static        <T> Forest<T> leaf(Token.Location loc, T tag) { return create(loc, tag, null, false, false); }
-    public static <T> Forest<T> create(Token.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
+    static        <T> Forest<T> singleton(Input.Location loc)                       { return create(loc, null, new Forest[] { }, false, true); }
+    static        <T> Forest<T> singleton(Input.Location loc, Forest<T> body)       { return create(loc, null, new Forest[] { body },  false, true); }
+    static        <T> Forest<T> leaf(Input.Location loc, T tag) { return create(loc, tag, null, false, false); }
+    public static <T> Forest<T> create(Input.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
         return new MultiForest<T>(loc, tag, tokens, unwrap, singleton);
     }
 
@@ -30,13 +30,13 @@ public abstract class Forest<T> {
 
     protected static class Body<T> {
 
-        private final Token.Location    location;
+        private final Input.Location    location;
         private final T                 tag;
         private final Forest<T>[]       tokens;
         private final boolean           unwrap;
         private final boolean           singleton;
 
-        private Body(Token.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
+        private Body(Input.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
             this.location = loc;
             this.tag = tag;
             this.tokens = tokens==null ? emptyForestArray : new Forest[tokens.length];
@@ -134,7 +134,7 @@ public abstract class Forest<T> {
     private static class MultiForest<T> extends IterableForest<T> {
         private final FastSet<Body<T>> results;
         private MultiForest(FastSet<Body<T>> results) { this.results = results; }
-        public MultiForest(Token.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
+        public MultiForest(Input.Location loc, T tag, Forest<T>[] tokens, boolean unwrap, boolean singleton) {
             this.results = new FastSet<Body<T>>(new Body(loc, tag, tokens, unwrap, singleton));
         }
         public Iterator<Body<T>> iterator() { return results.iterator(); }
index d25593f..bd2ecd6 100644 (file)
@@ -43,12 +43,12 @@ class GSS {
         private boolean good;
         private Phase next = null;
         private Phase prev;
-        private Token.Location location;
+        private Input.Location location;
         public final Parser parser;
 
         private Forest forest;
 
-        public Phase(Phase prev, Parser parser, Phase previous, Tok token, Token.Location location, Forest forest) {
+        public Phase(Phase prev, Parser parser, Phase previous, Tok token, Input.Location location, Forest forest) {
             this.prev = prev;
             this.forest = forest;
             this.parser = parser;
@@ -81,7 +81,7 @@ class GSS {
             return true;
         }
 
-        public Token.Location getLocation() { return location; }
+        public Input.Location getLocation() { return location; }
 
         /** add a new node (merging with existing nodes if possible)
          *  @param parent             the parent of the new node
similarity index 97%
rename from src/edu/berkeley/sbp/Token.java
rename to src/edu/berkeley/sbp/Input.java
index a662e8a..b326468 100644 (file)
@@ -7,7 +7,7 @@ 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 Token {
+public interface Input {
 
     /** this is declared abstract as a way of forcing subclasses to provide a thoughtful implementation */
     public abstract String toString();
index 9c0a3ad..75baf3a 100644 (file)
@@ -9,11 +9,11 @@ import java.util.*;
 
 /** thrown when the parser arrives at a state from which it is clear that no valid parse can result */
 public class ParseFailed extends RuntimeException {
-    private final Token.Location location;
+    private final Input.Location location;
     private final String message;
     public ParseFailed() { this("", null); }
-    public ParseFailed(String message, Token.Location loc) { this.location = loc; this.message = message; }
-    public Token.Location getLocation() { return location; }
+    public ParseFailed(String message, Input.Location loc) { this.location = loc; this.message = message; }
+    public Input.Location getLocation() { return location; }
     public String toString() { return message/* + (location==null ? "" : (" at " + location))*/; }
 
     public static <Tok> void complain(GSS.Phase<Tok>.Node n, HashMap<String,HashSet<String>> errors, boolean force) {
index 60da9e4..87b5508 100644 (file)
@@ -15,12 +15,12 @@ public abstract class Parser<Tok, Result> {
     protected Parser(Table<Tok> pt)               { this.pt = pt; }
 
     /** implement this method to create the output forest corresponding to a lone shifted input token */
-    public abstract Forest<Result> shiftToken(Tok t, Token.Location loc);
+    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(Token.Stream<Tok> input) throws IOException, ParseFailed {
+    public Forest<Result> parse(Input.Stream<Tok> input) throws IOException, ParseFailed {
         GSS gss = new GSS();
-        Token.Location loc = input.getLocation();
+        Input.Location loc = input.getLocation();
         GSS.Phase current = gss.new Phase<Tok>(null, this, null, input.next(1, 0, 0), loc, null);
         current.newNode(null, Forest.leaf(null, null), pt.start, true);
         int count = 1;
index ac34264..b31b307 100644 (file)
@@ -81,7 +81,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
         return epsilonForm;
     }
 
-    protected abstract <T> Forest<T> postReduce(Token.Location loc, Forest<T>[] args);
+    protected abstract <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args);
 
 
     // Position //////////////////////////////////////////////////////////////////////////////
@@ -123,12 +123,12 @@ public abstract class Sequence extends Element implements Iterable<Element> {
 
         // Position /////////////////////////////////////////////////////////////////////////////////
 
-        final <T> Forest<T> rewrite(Token.Location loc) {
+        final <T> Forest<T> rewrite(Input.Location loc) {
             if (this==firstp()) return epsilonForm();
             return rewrite2(loc);
         }
 
-        final <T> Forest<T> rewrite2(Token.Location loc) {
+        final <T> Forest<T> rewrite2(Input.Location loc) {
             for(int i=0; i<pos; i++) if (holder[i]==null) throw new Error("realbad " + i);
             for(int i=pos; i<elements.length; i++) {
                 if (holder[i]==null) holder[i] = elements[i].epsilonForm();
@@ -174,7 +174,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
     static class Constant extends Sequence {
         private final Object result;
         public Constant(Element[] e, Object result, HashSet<Sequence> and, HashSet<Sequence> not) { super(e, and, not); this.result = result; }
-        public <T> Forest<T> postReduce(Token.Location loc, Forest<T>[] args) {
+        public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args) {
             return (Forest<T>)Forest.leaf(loc, result);
         }
         static class Drop extends Constant {
@@ -190,14 +190,14 @@ public abstract class Sequence extends Element implements Iterable<Element> {
         private final int idx;
         public Singleton(Element e, HashSet<Sequence> and, HashSet<Sequence> not) { this(new Element[] { e }, 0, and, not); }
         public Singleton(Element[] e, int idx, HashSet<Sequence> and, HashSet<Sequence> not) { super(e, and, not); this.idx = idx; }
-        public <T> Forest<T> postReduce(Token.Location loc, Forest<T>[] args) { return (Forest<T>)Forest.singleton(loc, args[idx]); }
+        public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args) { return (Forest<T>)Forest.singleton(loc, args[idx]); }
     }
 
     public static class Unwrap extends Sequence {
         private boolean[] drops;
         public Unwrap(Element[] e, HashSet<Sequence> and, HashSet<Sequence> not)                  { super(e, and, not); this.drops = null; }
         public Unwrap(Element[] e, boolean[] drops, HashSet<Sequence> and, HashSet<Sequence> not) { super(e, and, not); this.drops = drops; }
-        public <T> Forest<T> postReduce(Token.Location loc, Forest<T>[] args) {
+        public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args) {
             for(int i=0; i<args.length; i++) if (args[i]==null) throw new Error();
             if (drops==null) return Forest.create(loc, null, args, true, false);
             int count = 0;
@@ -220,7 +220,7 @@ public abstract class Sequence extends Element implements Iterable<Element> {
             this.drops = drops == null ? new boolean[e.length] : drops;
             for(int i=0; i<this.drops.length; i++) if (!this.drops[i]) count++;
         }
-        public <T> Forest<T> postReduce(Token.Location loc, Forest<T>[] args) {
+        public <T> Forest<T> postReduce(Input.Location loc, Forest<T>[] args) {
             Forest<T>[] args2 = new Forest[count];
             int j = 0;
             for(int i=0; i<args.length; i++) if (!drops[i]) args2[j++] = args[i];
index 6b295a5..102817c 100644 (file)
@@ -11,7 +11,7 @@ public class Tree<T> extends PrintableTree<Tree<T>> implements Iterable<Tree<T>>
 
     final T           head;
           Tree<T>[]   children;
-    final Token.Location    location;
+    final Input.Location    location;
 
     public T                 head()        { return head; }
     public int               numChildren() { return children.length; }
@@ -19,10 +19,10 @@ public class Tree<T> extends PrintableTree<Tree<T>> implements Iterable<Tree<T>>
     public Iterator<Tree<T>> iterator()    { return new ArrayIterator(children); }
     public Tree<T>           child(int i)  { return children[i]; }
 
-    public       Token.Location    getLocation() { return location; }
+    public       Input.Location    getLocation() { return location; }
 
-    public Tree(Token.Location loc, T head)                   { this(loc, head, null); }
-    public Tree(Token.Location loc, T head, Tree<T>[] children) {
+    public Tree(Input.Location loc, T head)                   { this(loc, head, null); }
+    public Tree(Input.Location loc, T head, Tree<T>[] children) {
         this.location = loc;
         this.head = head;
         Tree<T>[] children2 = children==null ? new Tree[0] : new Tree[children.length];
index 380d09b..04e36ae 100644 (file)
@@ -75,9 +75,9 @@ abstract class Walk<T> {
     }
 
 
-    // Token-Set //////////////////////////////////////////////////////////////////////////////
+    // Input-Set //////////////////////////////////////////////////////////////////////////////
 
-    static abstract class WalkTokenSet<Tok extends Token> extends Walk<Topology<Tok>> {
+    static abstract class WalkTokenSet<Tok extends Input> extends Walk<Topology<Tok>> {
         public Topology<Tok> cs;
         public WalkTokenSet(Topology<Tok> cs)          { this.cs = cs; }
         public WalkTokenSet(Topology<Tok> cs, Cache c) { super(c); this.cs = cs; }
@@ -85,7 +85,7 @@ abstract class Walk<T> {
         public Topology<Tok> walkAtom(Atom r)          { cs = cs.union(r); return cs; }
     }
 
-    static class First<Tok extends Token> extends WalkTokenSet<Tok> {
+    static class First<Tok extends Input> extends WalkTokenSet<Tok> {
         public First(Topology<Tok> cs, Walk.Cache cache) { super(cs, cache); }
         public Topology<Tok> sequence(Sequence seq) {
             for(Position p = seq.firstp(); p!=null && !p.isLast(); p = p.next()) {
@@ -96,7 +96,7 @@ abstract class Walk<T> {
         }
     }
 
-    static class Follow<Tok extends Token> extends WalkTokenSet<Tok> {
+    static class Follow<Tok extends Input> extends WalkTokenSet<Tok> {
         private final Element me;
         private final HashSet<Element> all;
         private boolean eof = false;
@@ -172,7 +172,7 @@ abstract class Walk<T> {
         public HashMap<Element,Topology> follow = new HashMap<Element,Topology>();
         public HashMapBag<Element,Element>  ys = new HashMapBag<Element,Element>();
         public HashMap<Element,Topology> atoms = new HashMap<Element,Topology>();
-        public <Tok extends Token> Topology<Tok> first(Element e, Topology<Tok> empty) {
+        public <Tok extends Input> Topology<Tok> first(Element e, Topology<Tok> empty) {
             return new Walk.First<Tok>(empty, this).walk(e);
         }
     }
similarity index 87%
rename from src/edu/berkeley/sbp/misc/CharToStringParser.java
rename to src/edu/berkeley/sbp/chr/CharParser.java
index 1153e51..db235cd 100644 (file)
@@ -1,13 +1,14 @@
-package edu.berkeley.sbp.misc;
+package edu.berkeley.sbp.chr;
 import java.io.*;
 import java.util.*;
 import java.lang.reflect.*;
 import java.lang.ref.*;
 import edu.berkeley.sbp.*;
-import edu.berkeley.sbp.Token.Location;
 import edu.berkeley.sbp.util.*;
+import edu.berkeley.sbp.misc.*;
+import edu.berkeley.sbp.Input.Location;
 
-public class CharToStringParser extends Parser<Character,String> {
+public class CharParser extends Parser<Character,String> {
     public Forest<String> parse(InputStream is) throws IOException, ParseFailed {
         return super.parse(new Stream(is));
     }
@@ -15,7 +16,7 @@ public class CharToStringParser extends Parser<Character,String> {
         return super.parse(new Stream(r));
     }
 
-    public CharToStringParser(Union u) {
+    public CharParser(Union u) {
         super(u, new CharTopology());
         pt.optimize(new CharTopology());
     }
similarity index 94%
rename from src/edu/berkeley/sbp/misc/CharRange.java
rename to src/edu/berkeley/sbp/chr/CharRange.java
index 4fd319d..cac3bbb 100644 (file)
@@ -1,11 +1,12 @@
-package edu.berkeley.sbp.misc;
+package edu.berkeley.sbp.chr;
 import java.io.*;
 import java.util.*;
 import java.lang.reflect.*;
 import java.lang.ref.*;
 import edu.berkeley.sbp.*;
-import edu.berkeley.sbp.Token.Location;
 import edu.berkeley.sbp.util.*;
+import edu.berkeley.sbp.misc.*;
+import edu.berkeley.sbp.Input.Location;
 
 public class CharRange extends Atom<Character> {
 
similarity index 95%
rename from src/edu/berkeley/sbp/misc/CharTopology.java
rename to src/edu/berkeley/sbp/chr/CharTopology.java
index 81ab840..3a065d1 100644 (file)
@@ -1,5 +1,6 @@
-package edu.berkeley.sbp.misc;
+package edu.berkeley.sbp.chr;
 import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.misc.*;
 import edu.berkeley.sbp.util.*;
 
 public class CharTopology extends IntegerTopology<Character> implements Functor<Character,Integer> {
index cf477cc..200396e 100644 (file)
@@ -4,10 +4,10 @@ import java.util.*;
 import java.lang.reflect.*;
 import java.lang.ref.*;
 import edu.berkeley.sbp.*;
-import edu.berkeley.sbp.Token.Location;
+import edu.berkeley.sbp.Input.Location;
 import edu.berkeley.sbp.util.*;
 
-public abstract class CartesianInput<Tok> implements Token.Stream<Tok> {
+public abstract class CartesianInput<Tok> implements Input.Stream<Tok> {
 
     private int line  = 1;
     private int col   = 0;
@@ -16,8 +16,8 @@ public abstract class CartesianInput<Tok> implements Token.Stream<Tok> {
     public abstract boolean isCR();
 
     long then = 0;
-    private Token.Location location = new LocWrap(line, col);
-    public Token.Location getLocation() { return location; }
+    private Input.Location location = new LocWrap(line, col);
+    public Input.Location getLocation() { return location; }
     public Tok next(int numstates, int resets, int waits) throws IOException {
         Tok t = next();
         if (t==null) return null;
@@ -39,14 +39,14 @@ public abstract class CartesianInput<Tok> implements Token.Stream<Tok> {
         return t;
     }
 
-    public static class Location implements Token.Location {
+    public static class Location implements Input.Location {
         public final int line;
         public final int col;
         public String toString()            { return line + ":" + col; }
         public Location(int line, int col)  { this.line = line; this.col = col; }
     }
 
-    private class LocWrap implements Token.Location {
+    private class LocWrap implements Input.Location {
         public final int line;
         public final int col;
         public String toString()            { return line + ":" + col; }
index 4b5f707..03f8f97 100644 (file)
@@ -1,11 +1,21 @@
 package edu.berkeley.sbp.misc;
 import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
+import edu.berkeley.sbp.chr.*;
 import java.util.*;
 import java.io.*;
 
 public class MetaGrammar extends StringWalker {
 
+    public static class Hack<T extends Input> extends Atom<T> {
+        private final Atom<T> a;
+        static final Topology leftright = CharRange.rightBrace.union(CharRange.leftBrace);
+        public Hack(Atom<T> a) { this.a = a; }
+        public Topology<T> top() { return a.minus(leftright); }
+        public String toString() { return "~"+a; }
+    }
+
+
     public static Union make() throws Exception {
         return ((MetaGrammar)new MetaGrammar().walk(meta)).done();
     }
@@ -123,7 +133,7 @@ public class MetaGrammar extends StringWalker {
         else if ("psylr".equals(head)) throw new Error("not supported");
         else if ("/".equals(head)) return ((PreSequence)walk(tree, 0)).sparse((Element)walk(tree, 1));
         else if ("~".equals(head))
-            return new Atom.Hack(new Atom.Invert(new Atom.Infer((Element)walk(tree, 0))));
+            return new Hack(new Atom.Invert(new Atom.Infer((Element)walk(tree, 0))));
         else if ("ps".equals(head)) return new PreSequence((Element[])walk(tree, 0));
         else if ("ps".equals(head)) return new PreSequence((Element[])walk(tree, 0));
         else if ("qprod".equals(head)) {
@@ -278,7 +288,7 @@ public class MetaGrammar extends StringWalker {
         }
 
         out.append("\n        // DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED\n");
-        new CharToStringParser(MetaGrammar.make()).parse(new FileInputStream(args[0])).expand1().toJava(out);
+        new CharParser(MetaGrammar.make()).parse(new FileInputStream(args[0])).expand1().toJava(out);
         out.append("\n        // DO NOT EDIT STUFF ABOVE: IT IS AUTOMATICALLY GENERATED\n");
 
         for(String s = br.readLine(); s != null; s = br.readLine()) out.append(s+"\n");
index af92d0b..cf0b4e3 100644 (file)
@@ -4,6 +4,7 @@ import java.util.*;
 import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.misc.*;
 import edu.berkeley.sbp.tib.*;
+import edu.berkeley.sbp.chr.*;
 
 public class RegressionTests {
 
@@ -22,15 +23,15 @@ public class RegressionTests {
             //MetaGrammar mg0 = new MetaGrammar();
             //mg0.walk(MetaGrammar.meta);
             //System.out.println(mg0);
-            Tree<String> res = new CharToStringParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
+            Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
             MetaGrammar mg = (MetaGrammar)new MetaGrammar().walk(res);
             //System.out.println(mg);
             Union meta = mg.done();
             SequenceInputStream sis = new SequenceInputStream(new FileInputStream(s[0]), new FileInputStream(s[1]));
-            res = new CharToStringParser(meta).parse(sis).expand1();
+            res = new CharParser(meta).parse(sis).expand1();
             Union testcasegrammar = ((MetaGrammar)new MetaGrammar("ts").walk(res)).done("ts");
             if (testcasegrammar==null) return;
-            CharToStringParser parser = new CharToStringParser(testcasegrammar);
+            CharParser parser = new CharParser(testcasegrammar);
 
             if (profile) {
                 System.out.println("\nready...");
@@ -79,8 +80,8 @@ public class RegressionTests {
             ParseFailed pfe = null;
             try {
                 res = tib 
-                    ? /*new CharToStringParser(grammar).parse(new Tib(input))*/ null
-                : new CharToStringParser(grammar).parse(new StringReader(input));
+                    ? /*new CharParser(grammar).parse(new Tib(input))*/ null
+                : new CharParser(grammar).parse(new StringReader(input));
             } catch (ParseFailed pf) {
                 pfe = pf;
             }
index bab4eff..b21e458 100644 (file)
@@ -8,8 +8,8 @@ import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.util.*;
 import edu.berkeley.sbp.*;
 
-/** an implementation of Token for streams of Java <tt>char</tt> values */
-public class StringToken implements Token {
+/** an implementation of Input for streams of Java <tt>char</tt> values */
+public class StringToken implements Input {
 
     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; } };
index 4b4a247..15c286a 100644 (file)
@@ -5,6 +5,7 @@
 package edu.berkeley.sbp.tib;
 import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.misc.*;
+import edu.berkeley.sbp.chr.*;
 import java.util.*;
 import java.io.*;
 
@@ -23,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 Token.Stream<Character> {
+public class Tib implements Input.Stream<Character> {
 
     public Tib(String s) throws IOException { this(new StringReader(s)); }
     public Tib(Reader r) throws IOException { this(new BufferedReader(r)); }
@@ -41,7 +42,7 @@ public class Tib implements Token.Stream<Character> {
 
     int _row = 1;
     int _col = 0;
-    public Token.Location getLocation() { return new CartesianInput.Location(_row, _col); }
+    public Input.Location getLocation() { return new CartesianInput.Location(_row, _col); }
     private BufferedReader br;
 
     char left = CharRange.left;
index 2883508..553397b 100644 (file)
@@ -3,11 +3,10 @@
 // You may not use this file except in compliance with the License.
 
 package edu.berkeley.sbp.tib;
-//import org.ibex.util.*;
-//import org.ibex.io.*;
 import edu.berkeley.sbp.*;
 import edu.berkeley.sbp.misc.*;
 import edu.berkeley.sbp.util.*;
+import edu.berkeley.sbp.chr.*;
 import java.util.*;
 import java.io.*;
 
@@ -15,13 +14,13 @@ public class TibDoc {
 
     public static void main(String[] s) throws Exception {
         System.out.println("parsing " + s[0]);
-        Tree<String> res = new CharToStringParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
+        Tree<String> res = new CharParser(MetaGrammar.make()).parse(new FileInputStream(s[0])).expand1();
         MetaGrammar gram = (MetaGrammar)new Tib.Grammar().walk(res);
         //System.out.println(gram);
         Union mg = gram.done();
         
         System.out.println("\nparsing " + s[1]);
-        Forest f = new CharToStringParser(mg).parse(new Tib(new FileInputStream(s[1])));
+        Forest f = new CharParser(mg).parse(new Tib(new FileInputStream(s[1])));
 
         System.out.println();
         System.out.println(f);