checkpoint
authoradam <adam@megacz.com>
Wed, 14 Dec 2005 21:58:51 +0000 (16:58 -0500)
committeradam <adam@megacz.com>
Wed, 14 Dec 2005 21:58:51 +0000 (16:58 -0500)
darcs-hash:20051214215851-5007d-6cf7f3727613a26e9df2df9436857d93b69193fe.gz

TODO
src/edu/berkeley/sbp/misc/MetaGrammar.java
src/edu/berkeley/sbp/misc/ReflectiveWalker.java
tests/meta.g

diff --git a/TODO b/TODO
index 972a801..5368def 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,6 +1,9 @@
-______________________________________________________________________________
+_____________________________________________________________________________
 Immediately
 
+  - Lay down the law on the different kinds of Sequence productions
+    and how they work.
+
   - switch maximal to not-followed-by (~/~)
 
   - should Union.add() be there?
index 687d2d8..71782dd 100644 (file)
@@ -55,7 +55,7 @@ public class MetaGrammar extends ReflectiveWalker {
     public Element     _rightparen_(Object e)                                         { return SELF; }
     public Element     _bang_(Element r)                                              { return r; }
     public Object      _caret_(String s)                                              { return new MyLift(s); }
-    public Object      _leftparen__rightparen_()                                      { return epsilon; }
+    public Object      _leftparen__rightparen_(Object o)                              { return epsilon; }
     public Union       nonTerminal(String s)                                          { return nonTerminal(s, null, false, false); }
     public Union       _colon__colon__equals_(String s, PreSequence[][] p)            { return nonTerminal(s, p, false, false); }
     public Union       _bang__colon__colon__equals_(String s, PreSequence[][] p)      { return nonTerminal(s, p, false, true); }
@@ -154,6 +154,7 @@ public class MetaGrammar extends ReflectiveWalker {
             for(Sequence s : not) u.add(s);
             HashSet<Sequence> set = new HashSet<Sequence>();
             Element[] o2 = o==null ? new Element[0] : new Element[o.length];
+            int nonDrop = 0;
             if (o != null) {
                 drops = new boolean[o.length];
                 int j = 0;
@@ -162,10 +163,11 @@ public class MetaGrammar extends ReflectiveWalker {
                     if (oi instanceof MyDrop)      { oi = ((MyDrop)oi).o; drops[j] = true; }
 
                     if (oi==SELF)                    o2[j] = u.new Subset("(("+u+"))", set);
-                    else if (oi instanceof MyLift) { o2[j] = CharToken.string(tag = ((MyLift)oi).s); drops[j] = true; }
+                    else if (oi instanceof MyLift) { o2[j] = CharToken.string(tag = ((MyLift)oi).s); drops[j] = o.length>1; }
                     else                             o2[j] = (Element)oi;
 
                     if (MetaGrammar.dropAll.contains(o2[j])) drops[j] = true;
+                    nonDrop += drops[j] ? 0 : 1;
                     o2[j] = o2[j];
                     j++;
                 }
index 2334d62..71e597c 100644 (file)
@@ -53,11 +53,18 @@ public class ReflectiveWalker extends StringWalker {
         }
         return ret.toString();
     }
+    public Object walk(Tree<String> tree) {
+        if (tree.head()!=null) {
+            Member m = member("$"+normalize(tree.head()), 0, false);
+        }
+        return super.walk(tree);
+    }
     public Object walk(String tag, Object[] argo) {
         if (argo.length==0) return super.walk(tag, argo);
         if (argo==null) return tag;
         if (tag==null || "".equals(tag)) return argo;
-        Member m = member(normalize(tag), argo.length);
+        Member m = member(normalize(tag), argo.length, argo.length>0);
+        if (m==null) return super.walk(tag, argo);
         //System.out.println("preparing to invoke method " + (m==null ? "null" : (m.toString())) + " for sequence " + (owner()+"."+tag));
         if (m != null) return Reflection.fuzzyInvoke(target, m, argo);
         if (argo.length==0) return null;
@@ -69,14 +76,17 @@ public class ReflectiveWalker extends StringWalker {
         return ret;
     }
 
-    public Member member(String methodName, int nonVoid) {
+    public Member member(String methodName, int nonVoid, boolean complain) {
         Class target = this.target.getClass();
         if (methodName == null || methodName.equals("")) return null;
         Member ret = null;
         for (Method m : target.getMethods()) {
             if (!m.getName().equals(methodName)) continue;
             if (m.getParameterTypes().length != nonVoid) continue;
-            if (ret != null) throw new Error("two methods with " + nonVoid + " parameters: " + target.getName() + "." + methodName);
+            if (ret != null) {
+                if (!complain) return null;
+                throw new Error("two methods with " + nonVoid + " parameters: " + target.getName() + "." + methodName);
+            }
             ret = m;
         }
         if (ret != null) return ret;
@@ -86,7 +96,10 @@ public class ReflectiveWalker extends StringWalker {
             if (c != null) {
                 for (Constructor m : c.getConstructors()) {
                     if (m.getParameterTypes().length != nonVoid) continue;
-                    if (ret != null) throw new Error("two constructors with " + nonVoid + " parameters: " + c.getName() + ".<init>()");
+                    if (ret != null) {
+                        if (!complain) return null;
+                        throw new Error("two constructors with " + nonVoid + " parameters: " + c.getName() + ".<init>()");
+                    }
                     ret = m;
                 }
                 if (ret != null) return ret;
@@ -94,6 +107,7 @@ public class ReflectiveWalker extends StringWalker {
             t = t.getSuperclass();
         }
         if (ret != null) return ret;
+        if (!complain) return null;
         throw new Error("while computing return type of " +methodName+ " could not find method with name " + methodName +
                         " and " + nonVoid + " arguments");
     }
index bb7cd11..2779b7c 100644 (file)
@@ -21,8 +21,9 @@ ec       ::= [~\-\]\\\~]
 range    ::= ec          => "range"
            | ec ^"-" ec
 
-e        ::= word                             => "nonTerminal"
-           |    [(][)]                        => "epsilon"
+e        ::= word                           => "nonTerminal"
+           |  quoted                        => "literal"
+           |    ^"()"
            |    ^"{" alternatives "}"   /ws
            |    ^"["  (range*) "]"
            |    ^"[~" (range*) "]"
@@ -35,10 +36,8 @@ e        ::= word                             => "nonTerminal"
            |  e ^"+/" e                 /ws
            |  e ^"?"                    /ws
 
-           |  quoted                        => "literal"
-
-           |     "(" word ^")"          /ws
-           >    ^"(" alternatives ")"   /ws
+           |     "(" word         ^")"  /ws
+           >    ^"(" alternatives  ")"  /ws
 
 w       !::= " "
            | "//" ([~\n]*) "\n"