From: adam Date: Wed, 5 Jul 2006 02:20:22 +0000 (-0400) Subject: checkpoint X-Git-Tag: tag_for_25-Mar~217 X-Git-Url: http://git.megacz.com/?p=sbp.git;a=commitdiff_plain;h=0eb9557f0e79be770ffaa87a36a4be7843f3d9f5 checkpoint darcs-hash:20060705022022-5007d-e5a7b94b75c33bb6b6599839688814bfd504054e.gz --- diff --git a/src/edu/berkeley/sbp/misc/Demo.java b/src/edu/berkeley/sbp/misc/Demo.java index 82741d6..d29a8f9 100644 --- a/src/edu/berkeley/sbp/misc/Demo.java +++ b/src/edu/berkeley/sbp/misc/Demo.java @@ -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 ""; } - } - /** - * 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; @@ -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 boolean isRaw() { return _bindable.isAnnotationPresent(raw.class); } + public boolean isRaw() { return _bindable.isAnnotationPresent(bind.raw.class); } public Object invokeRaw(Iterable> t) { return _bindable.impose(new Object[] { t }); } public boolean isCompatible(Production p) { @@ -214,7 +216,7 @@ public class Demo { 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 t) { + public static @bind.as("grammaro") @bind.raw Object grammaro(Iterable t) { System.out.println("working on " + t); return Demo.make(t.iterator().next(), "s", new ReflectiveMetaPlain()); } diff --git a/src/edu/berkeley/sbp/tib/TibDoc.java b/src/edu/berkeley/sbp/tib/TibDoc.java index 572ccbe..d2d1f75 100644 --- a/src/edu/berkeley/sbp/tib/TibDoc.java +++ b/src/edu/berkeley/sbp/tib/TibDoc.java @@ -331,12 +331,12 @@ toContex ll = prefix ++ (concatMap tl ll) ++ suffix 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 @arg KeyVal[] attrs; + public @bind.arg KeyVal[] attrs; // 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 @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 { }