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); }
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;
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++;
}
}
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;
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;
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;
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");
}