// Typing Support //////////////////////////////////////////////////////////////////////////////
- public Number coerceToNumber() { throw new JSRuntimeExn("tried to coerce a JavaScript object to a Number"); }
- public String coerceToString() { throw new JSRuntimeExn("tried to coerce a JavaScript object to a String"); }
- public boolean coerceToBoolean() { throw new JSRuntimeExn("tried to coerce a JavaScript object to a Boolean"); }
+ public Number coerceToNumber() { throw new JSRuntimeExn("tried to coerce a JavaScript object of type " +
+ getClass().getName() + " to a Number"); }
+ public String coerceToString() { throw new JSRuntimeExn("tried to coerce a JavaScript object of type " +
+ getClass().getName() + " to a String"); }
+ public boolean coerceToBoolean() { throw new JSRuntimeExn("tried to coerce a JavaScript object of type " +
+ getClass().getName() + " to a Boolean"); }
public String typeName() { return "object"; }
if (g != null)
switch(tok) {
case BITOR: return new Grammar.Alternative(g, parseGrammar(null));
- case ADD: return new Grammar.Repetition(g, 1, Integer.MAX_VALUE);
- case MUL: return new Grammar.Repetition(g, 0, Integer.MAX_VALUE);
- case HOOK: return new Grammar.Repetition(g, 0, 1);
+ case ADD: return parseGrammar(new Grammar.Repetition(g, 1, Integer.MAX_VALUE));
+ case MUL: return parseGrammar(new Grammar.Repetition(g, 0, Integer.MAX_VALUE));
+ case HOOK: return parseGrammar(new Grammar.Repetition(g, 0, 1));
}
Grammar g0 = null;
switch(tok) {
default: pushBackToken(); return g;
}
if (g == null) return parseGrammar(g0);
- return new Grammar.Juxtaposition(g, g0);
+ return parseGrammar(new Grammar.Juxtaposition(g, g0));
}
/**
throw new Error("this should never happen");
}
+ private static Object NULL = new Object();
+
public abstract int match(String s, int start, Hash v, JSScope scope) throws JSExn;
public int matchAndWrite(final String s, final int start, Hash v, JSScope scope, String key) throws JSExn {
final Hash v2 = new Hash();
final int ret = match(s, start, v2, scope);
- if (ret == -1) return -1;
- Object result = action == null ?
+ Object result = ret == -1 ? NULL : action == null ?
s.substring(start, ret) :
action.cloneWithNewParentScope(new JSScope(scope) {
public Object get(Object key) throws JSExn {
- if (v2.get(key) != null) return v2.get(key);
+ Object val = v2.get(key);
+ if (val == NULL) return null;
+ if (val != null) return val;
if (key.equals("whole")) return s.substring(start, ret);
return super.get(key);
}
}).call(null, null, null, null, 0);
if (key != null) {
Object old = v.get(key);
- if (old == null) { }
- else if (old instanceof JSArray) { ((JSArray)old).addElement(result); result = old; }
- else { JSArray j = new JSArray(); j.addElement(old); j.addElement(result); result = j; }
+ if (old == null || old == NULL) { }
+ else if (old instanceof JSArray) { if (result != NULL) { ((JSArray)old).addElement(result); result = old; } }
+ else if (result != NULL) { JSArray j = new JSArray(); j.addElement(old); j.addElement(result); result = j; }
v.put(key, result);
}
return ret;