checkpoint
authoradam <adam@megacz.com>
Wed, 5 Jul 2006 02:20:22 +0000 (22:20 -0400)
committeradam <adam@megacz.com>
Wed, 5 Jul 2006 02:20:22 +0000 (22:20 -0400)
darcs-hash:20060705022022-5007d-e5a7b94b75c33bb6b6599839688814bfd504054e.gz

src/edu/berkeley/sbp/misc/Demo.java
src/edu/berkeley/sbp/misc/RegressionTests.java
src/edu/berkeley/sbp/tib/TibDoc.java

index 82741d6..d29a8f9 100644 (file)
@@ -122,49 +122,51 @@ public class Demo {
     }
 
     
     }
 
     
-    /**
-     *  Constructors, classes, and methods with this attribute will
-     *  match every production of the nonterminal called "value()"
-     *  that is arg-compatible.  If value() is undefined, then the
-     *  class/constructor/method name is used.
-     */ 
-    /*
-    @Retention(RetentionPolicy.RUNTIME) public static @interface nonterminal { String value() default ""; }
-    */
-
-    @Retention(RetentionPolicy.RUNTIME) public static @interface raw { }
-
-    /**
-     *  Constructors, classes, and methods with this attribute will
-     *  match every tree tagged with "value()" that is arg-compatible.
-     *  If value() is undefined, then the class/constructor/method
-     *  name is used.
-     */ 
-    public static class bind {
+    public static class bind {    
+        /**
+         *  Constructors, classes, and methods with this attribute will
+         *  match every production of the nonterminal called "value()"
+         *  that is arg-compatible.  If value() is undefined, then the
+         *  class/constructor/method name is used.
+         */ 
+        /*
+          @Retention(RetentionPolicy.RUNTIME) public static @interface nonterminal { String value() default ""; }
+        */
+
+        @Retention(RetentionPolicy.RUNTIME) public static @interface raw { }
+
+        /**
+         *  Constructors, classes, and methods with this attribute will
+         *  match every tree tagged with "value()" that is arg-compatible.
+         *  If value() is undefined, then the class/constructor/method
+         *  name is used.
+         */ 
+
         @Retention(RetentionPolicy.RUNTIME) public static @interface as         { String value() default ""; }
         @Retention(RetentionPolicy.RUNTIME) public static @interface as         { String value() default ""; }
-    }
 
 
-    /**
-     *  If any parameter to a method or field in a class has a named
-     *  arg-tag, that parameter/field matches the child of the tree
-     *  which either has that label or else is a reference to a
-     *  nonterminal with the corresponding name.
-     *  
-     *  The remaining non-named arg-tags match the remaining children
-     *  of the tree in sequential order.
-     *
-     *  If any arg-tagged parameters/fields remain, the match fails.
-     *  If there were no arg-tagged parameters-fields, it is as if all
-     *  of them were non-named and arg-tagged.
-     *
-     *  A method/constructor is arg-compatible if all of its arguments
-     *  are arg-compatible.
-     *
-     *  A class is arg-compatible if all of its fields are
-     *  arg-compatible, or if one of its constructors is arg-compatible.
-     *
-     */
-    @Retention(RetentionPolicy.RUNTIME) public static @interface arg         { String value() default ""; }
+
+        /**
+         *  If any parameter to a method or field in a class has a named
+         *  arg-tag, that parameter/field matches the child of the tree
+         *  which either has that label or else is a reference to a
+         *  nonterminal with the corresponding name.
+         *  
+         *  The remaining non-named arg-tags match the remaining children
+         *  of the tree in sequential order.
+         *
+         *  If any arg-tagged parameters/fields remain, the match fails.
+         *  If there were no arg-tagged parameters-fields, it is as if all
+         *  of them were non-named and arg-tagged.
+         *
+         *  A method/constructor is arg-compatible if all of its arguments
+         *  are arg-compatible.
+         *
+         *  A class is arg-compatible if all of its fields are
+         *  arg-compatible, or if one of its constructors is arg-compatible.
+         *
+         */
+        @Retention(RetentionPolicy.RUNTIME) public static @interface arg         { String value() default ""; }
+    }
 
     public static class Production {
         public String tag;
 
     public static class Production {
         public String tag;
@@ -195,7 +197,7 @@ public class Demo {
         //public nonterminal getNonTerminal() { return (nonterminal)_bindable.getAnnotation(bind.as.class); }
         public String toString() { return _bindable.getSimpleName(); }
         public Object plant(Object[] fields) { return _bindable.impose(fields); }
         //public nonterminal getNonTerminal() { return (nonterminal)_bindable.getAnnotation(bind.as.class); }
         public String toString() { return _bindable.getSimpleName(); }
         public Object plant(Object[] fields) { return _bindable.impose(fields); }
-        public boolean isRaw() { return _bindable.isAnnotationPresent(raw.class); }
+        public boolean isRaw() { return _bindable.isAnnotationPresent(bind.raw.class); }
         public Object invokeRaw(Iterable<Tree<Object>> t) { return _bindable.impose(new Object[] { t }); }
 
         public boolean isCompatible(Production p) {
         public Object invokeRaw(Iterable<Tree<Object>> t) { return _bindable.impose(new Object[] { t }); }
 
         public boolean isCompatible(Production p) {
@@ -214,7 +216,7 @@ public class Demo {
             return false;
         }
 
             return false;
         }
 
-        public int[] buildSequence(Production p, String[] names, arg[] argtags) {
+        public int[] buildSequence(Production p, String[] names, bind.arg[] argtags) {
             int argTagged = 0;
             for(int i=0; i<argtags.length; i++)
                 if (argtags[i] != null)
             int argTagged = 0;
             for(int i=0; i<argtags.length; i++)
                 if (argtags[i] != null)
@@ -280,10 +282,10 @@ public class Demo {
         public int[] buildSequence(Production p) {
             Field[]  f       = _class.getDeclaredFields();
             String[] names   = new String[f.length];
         public int[] buildSequence(Production p) {
             Field[]  f       = _class.getDeclaredFields();
             String[] names   = new String[f.length];
-            arg[]    argtags = new arg[f.length];
+            bind.arg[]    argtags = new bind.arg[f.length];
             for(int i=0; i<f.length; i++) {
                 names[i]   = f[i].getName();
             for(int i=0; i<f.length; i++) {
                 names[i]   = f[i].getName();
-                argtags[i] = f[i].getAnnotation(arg.class);
+                argtags[i] = f[i].getAnnotation(bind.arg.class);
             }
             int[] ret = buildSequence(p, names, argtags);
             if (ret!=null) return ret;
             }
             int[] ret = buildSequence(p, names, argtags);
             if (ret!=null) return ret;
@@ -309,11 +311,11 @@ public class Demo {
             }
             */
             String[] names   = new String[len];
             }
             */
             String[] names   = new String[len];
-            arg[]    argtags = new arg[len];
+            bind.arg[]    argtags = new bind.arg[len];
             for(int i=0; i<names.length; i++)
                 for(Annotation a : annotations[i+ofs])
             for(int i=0; i<names.length; i++)
                 for(Annotation a : annotations[i+ofs])
-                    if (a instanceof arg)
-                        argtags[i+ofs] = (arg)a;
+                    if (a instanceof bind.arg)
+                        argtags[i+ofs] = (bind.arg)a;
             return buildSequence(p, names, argtags);
         }
     }
             return buildSequence(p, names, argtags);
         }
     }
@@ -323,11 +325,11 @@ public class Demo {
         public int[] buildSequence(Production p) {
             Annotation[][] annotations = _method.getParameterAnnotations();
             String[] names   = new String[annotations.length];
         public int[] buildSequence(Production p) {
             Annotation[][] annotations = _method.getParameterAnnotations();
             String[] names   = new String[annotations.length];
-            arg[]    argtags = new arg[annotations.length];
+            bind.arg[]    argtags = new bind.arg[annotations.length];
             for(int i=0; i<names.length; i++)
                 for(Annotation a : annotations[i])
             for(int i=0; i<names.length; i++)
                 for(Annotation a : annotations[i])
-                    if (a instanceof arg)
-                        argtags[i] = (arg)a;
+                    if (a instanceof bind.arg)
+                        argtags[i] = (bind.arg)a;
             int[] ret = buildSequence(p, names, argtags);
             return ret;
         }
             int[] ret = buildSequence(p, names, argtags);
             return ret;
         }
@@ -373,7 +375,7 @@ public class Demo {
                         return nt;
                 return null;
             }
                         return nt;
                 return null;
             }
-            public @arg("NonTerminal") NonTerminal[] nonterminals;
+            public @bind.arg("NonTerminal") NonTerminal[] nonterminals;
             public String toString() {
                 String ret = "[ ";
                 for(NonTerminal nt : nonterminals) ret += nt + ", ";
             public String toString() {
                 String ret = "[ ";
                 for(NonTerminal nt : nonterminals) ret += nt + ", ";
@@ -404,8 +406,8 @@ public class Demo {
         }
         public static class NonTerminal extends Un {
             public String  name = null;
         }
         public static class NonTerminal extends Un {
             public String  name = null;
-            public @bind.as("=") NonTerminal(@arg("Word") String name,
-                                         @arg("RHS") Seq[][] sequences) {
+            public @bind.as("=") NonTerminal(@bind.arg("Word") String name,
+                                         @bind.arg("RHS") Seq[][] sequences) {
                 this.name = name;
                 this.sequences = sequences;
             }
                 this.name = name;
                 this.sequences = sequences;
             }
@@ -539,7 +541,7 @@ public class Demo {
         public static @bind.as("()")  El   epsilon()                         { return new Constant(Union.epsilon); }
 
         public static @bind.as("nonTerminal") class NonTerminalReference extends El {
         public static @bind.as("()")  El   epsilon()                         { return new Constant(Union.epsilon); }
 
         public static @bind.as("nonTerminal") class NonTerminalReference extends El {
-            public @arg String nonTerminal;
+            public @bind.arg String nonTerminal;
             public Element build(Context cx) {
                 return cx.get(nonTerminal);
             }
             public Element build(Context cx) {
                 return cx.get(nonTerminal);
             }
@@ -562,7 +564,7 @@ public class Demo {
         }
 
         public static @bind.as("{")           class XTree                 extends El {
         }
 
         public static @bind.as("{")           class XTree                 extends El {
-            public @arg Seq body;
+            public @bind.arg Seq body;
             public Element build(Context cx) {
                 throw new Error();
             }
             public Element build(Context cx) {
                 throw new Error();
             }
index 3255630..eac2ea6 100644 (file)
@@ -103,7 +103,7 @@ public class RegressionTests {
             });
         }
         public static class TestCaseMakerHelper extends MG {
             });
         }
         public static class TestCaseMakerHelper extends MG {
-            public static @bind.as("grammaro") @raw Object grammaro(Iterable<Tree> t) {
+            public static @bind.as("grammaro") @bind.raw Object grammaro(Iterable<Tree> t) {
                 System.out.println("working on " + t);
                 return Demo.make(t.iterator().next(), "s", new ReflectiveMetaPlain());
             }
                 System.out.println("working on " + t);
                 return Demo.make(t.iterator().next(), "s", new ReflectiveMetaPlain());
             }
index 572ccbe..d2d1f75 100644 (file)
@@ -331,12 +331,12 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix
     public static class TD {
 
         public @bind.as static class Doc extends Dump {
     public static class TD {
 
         public @bind.as static class Doc extends Dump {
-            public @arg Header head;
-            public @arg Body body;
+            public @bind.arg Header head;
+            public @bind.arg Body body;
         }
 
         public @bind.as static class Header extends Dump {
         }
 
         public @bind.as static class Header extends Dump {
-            public @arg KeyVal[] attrs;
+            public @bind.arg KeyVal[] attrs;
             // FIXME: it would be nice to be able to
             // void KeyVal(String, String) { ... } imperatively
         }
             // FIXME: it would be nice to be able to
             // void KeyVal(String, String) { ... } imperatively
         }
@@ -351,8 +351,8 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix
         }
         
         public @bind.as static class KeyVal extends Dump {
         }
         
         public @bind.as static class KeyVal extends Dump {
-            public @arg String key;
-            public @arg Object val;
+            public @bind.arg String key;
+            public @bind.arg Object val;
         }
 
         public abstract static class Paragraph extends Dump implements ToHTML { }
         }
 
         public abstract static class Paragraph extends Dump implements ToHTML { }