}
- /**
- * 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;
//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) {
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)
for(int i=0; i<o.length; i++) o2[map[i]] = o[i];
return plant(o2);
}
+ public int[] buildSequence(Production p) {
+ Annotation[][] annotations = _bindable.getArgAnnotations();
+ String[] names = _bindable.getArgNames();
+ String name = _bindable.getSimpleName();
+ int len = annotations.length;
+ int ofs = 0;
+ bind.arg[] argtags = new bind.arg[len];
+ for(int i=0; i<names.length; i++)
+ for(Annotation a : annotations[i+ofs])
+ if (a instanceof bind.arg)
+ argtags[i+ofs] = (bind.arg)a;
+ return Target.this.buildSequence(p, names, argtags);
+ }
}
}
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();
- 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;
ofs++;
}
*/
- String[] names = new String[len];
- arg[] argtags = new arg[len];
+ String[] names = new String[len];
+ bind.arg[] argtags = new bind.arg[len];
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);
}
}
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])
- 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;
}
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 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;
}
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 static @bind.as("{") class XTree extends El {
- public @arg Seq body;
+ public @bind.arg Seq body;
public Element build(Context cx) {
throw new Error();
}