checkpoint
authoradam <adam@megacz.com>
Sun, 28 May 2006 08:06:25 +0000 (04:06 -0400)
committeradam <adam@megacz.com>
Sun, 28 May 2006 08:06:25 +0000 (04:06 -0400)
darcs-hash:20060528080625-5007d-ddb2469882433cd8b5e4e500bb57898de9945170.gz

src/edu/berkeley/sbp/Repeat.java
src/edu/berkeley/sbp/Sequence.java
src/edu/berkeley/sbp/misc/MetaGrammar.java
src/edu/berkeley/sbp/misc/MetaGrammarTree.java

index ae2a77b..9cce700 100644 (file)
@@ -29,17 +29,17 @@ import java.lang.ref.*;
     }
 
     public static class Maximal extends Repeat {
-        public Maximal(final Element e, boolean zeroOkay, boolean manyOkay, final Element separator, Object tag) {
+        public Maximal(final Element e, boolean zeroOkay, boolean manyOkay, final Atom separator, Object tag) {
             super(e, zeroOkay, manyOkay, separator, true, tag);
             if (zeroOkay && separator != null)
                 throw new RuntimeException("cannot create a maximal repetition of zero or more items with a separator (yet): " + this);
             for(Sequence s : this)
-                s.follow = new edu.berkeley.sbp.misc.MetaGrammar.Invert(new edu.berkeley.sbp.misc.MetaGrammar.Infer(separator));
+                s.follow = new edu.berkeley.sbp.misc.MetaGrammar.Invert(separator);
         }
-        public Maximal(final Element e, boolean zeroOkay, boolean manyOkay, Object tag) {
+        public Maximal(final Atom e, boolean zeroOkay, boolean manyOkay, Object tag) {
             super(e, zeroOkay, manyOkay, null, true, tag);
             for(Sequence s : this)
-                s.follow = new edu.berkeley.sbp.misc.MetaGrammar.Invert(new edu.berkeley.sbp.misc.MetaGrammar.Infer(e));
+                s.follow = new edu.berkeley.sbp.misc.MetaGrammar.Invert(e);
         }
     }
 
index 70b6b57..e5e984f 100644 (file)
@@ -271,14 +271,14 @@ public abstract class Sequence extends Element implements Iterable<Element> {
     public  static Repeat many1(Element e, Element sep, Object tag)    { return new Repeat(e, false, true, sep, tag); }
 
     /** repeat zero or more times, matching a maximal sequence of atoms */
-    public  static Repeat maximal0(Element e)                          { return new Repeat.Maximal(e, true, true, null); }
-    public  static Repeat maximal0(Element e, Object tag)              { return new Repeat.Maximal(e, true, true, tag); }
+    public  static Repeat maximal0(Atom e)                             { return new Repeat.Maximal(e, true, true, null); }
+    public  static Repeat maximal0(Atom e, Object tag)                 { return new Repeat.Maximal(e, true, true, tag); }
     /** repeat one or more times, matching a maximal sequence of atoms */
-    public  static Repeat maximal1(Element e)                          { return new Repeat.Maximal(e, false, true, null); }
-    public  static Repeat maximal1(Element e, Object tag)              { return new Repeat.Maximal(e, false, true, tag); }
+    public  static Repeat maximal1(Atom e)                             { return new Repeat.Maximal(e, false, true, null); }
+    public  static Repeat maximal1(Atom e, Object tag)                 { return new Repeat.Maximal(e, false, true, tag); }
     /** repeat one or more times, separated by an atom <tt>sep</tt>, matching a maximal sequence */
-    public  static Repeat maximal1(Element e, Element sep)             { return new Repeat.Maximal(e, false, true, sep, null); }
-    public  static Repeat maximal1(Element e, Element sep, Object tag) { return new Repeat.Maximal(e, false, true, sep, tag); }
+    public  static Repeat maximal1(Element e, Atom sep)                { return new Repeat.Maximal(e, false, true, sep, null); }
+    public  static Repeat maximal1(Element e, Atom sep, Object tag)    { return new Repeat.Maximal(e, false, true, sep, tag); }
 
 
 }
index 3f2ffc7..285016b 100644 (file)
@@ -17,6 +17,8 @@ public class MetaGrammar extends StringWalker {
         public String toString() { return e.toString(); }
     }
 
+    public static Atom infer(Element e) { return new CharRange((Topology<Character>)Atom.toAtom(e)); }
+
     /** an atom which tracks the inverse of some other atom */
     public static class Invert<T extends Input> extends Atom<T> {
         private final Atom<T> a;
@@ -225,7 +227,7 @@ public class MetaGrammar extends StringWalker {
                     if (idx != -1) ret = Sequence.singleton(els, idx);
                     else           ret = Sequence.drop(els, false);
                 }
-                if (this.followedBy != null) ret.follow = new Hack(new Infer(this.followedBy.build(bc)));
+                if (this.followedBy != null) ret.follow = new Hack(infer(this.followedBy.build(bc)));
                 return ret;
             }
             private MetaConjunct(Tree<String> t) {
@@ -305,8 +307,8 @@ public class MetaGrammar extends StringWalker {
                     return !maximal
                         ? new Repeat(element.build(bc), zero, many, separator==null?null:separator.build(bc), null)
                         : separator==null
-                              ? new Repeat.Maximal(element.build(bc), zero, many, null)
-                        : new Repeat.Maximal(element.build(bc), zero, many, separator.build(bc), null);
+                        ? new Repeat.Maximal(infer(element.build(bc)), zero, many, null)
+                        : new Repeat.Maximal(element.build(bc), zero, many, infer(separator.build(bc)), null);
                 }
                 public MetaRepeat(MetaClause element, boolean maximal, MetaClause separator, boolean zero, boolean many) {
                     this.separator = separator;
@@ -377,7 +379,7 @@ public class MetaGrammar extends StringWalker {
                 public MetaClause element;
                 public MetaInvert(Tree<String> t, MetaConjunct c) { this.element = make(t, c); }
                 public String toString() { return "~"+element; }
-                public Element build(BuildContext bc) { return new Hack(new Invert(new Infer(element.build(bc)))); }
+                public Element build(BuildContext bc) { return new Hack(new Invert(infer(element.build(bc)))); }
             }
         }
 
index a6f88b0..0f40fed 100644 (file)
@@ -41,6 +41,9 @@ public class MetaGrammarTree {
 
 
 
+
+
+
         // DO NOT EDIT STUFF BELOW: IT IS AUTOMATICALLY GENERATED
 new edu.berkeley.sbp.Tree(null, "grammar", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "=", new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, null, new edu.berkeley.sbp.Tree[] { new edu.berkeley.sbp.Tree(null, "G", new edu.berkeley.sbp.Tree[] { }),
         new edu.berkeley.sbp.Tree(null, "r", new edu.berkeley.sbp.Tree[] { }),
@@ -558,3 +561,6 @@ new edu.berkeley.sbp.Tree(null, "grammar", new edu.berkeley.sbp.Tree[] { new edu
 
 
 
+
+
+