A FallbackMatcher uses another Matcher (the fallback) if it cannot find the type or value
of a given symbol. It never modifies the contents of the fallback.
publicclassFallbackMatcherextendsMatcher {
privateMatcher fallback;
publicFallbackMatcher(Matcher fallback) {
this.fallback = fallback;
}
public Object clone() {
thrownew Error("sorry, no clone (yet).");
}
publicPart getPatternType(String symbol) {
Part result = super.getPatternType(symbol);
if (result == null) result = fallback.getPatternType(symbol);
return result;
}
publicPart getPatternType(Identifier symbol) { return getPatternType(symbol.getString()); }
publicPart getTomatchType(String symbol) {
Part result = super.getTomatchType(symbol);
if (result == null) result = fallback.getTomatchType(symbol);
return result;
}
publicPart getMatchedValue(String symbol) {
Part result = super.getMatchedValue(symbol);
if (result == null) result = fallback.getMatchedValue(symbol);
return result;
}
public Enumeration tomatchSymbols() {
returnnewFallbackEnumeration(super.tomatchSymbols(),fallback.tomatchSymbols());
}
public Enumeration matchedSymbols() {
returnnewFallbackEnumeration(super.matchedSymbols(),fallback.matchedSymbols());
}
publicvoid dump() {
fallback.dump();
super.dump();
}
protectedboolean isFunction(String fname) {
if(super.isFunction(fname)) return true;
return fallback.isFunction(fname);
}
}