2004/01/08 05:32:44
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:44:08 +0000 (07:44 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:44:08 +0000 (07:44 +0000)
darcs-hash:20040130074408-2ba56-baa23e3de418876fe0c14da1f38be569f365de7c.gz

src/org/xwt/js/JS.java
src/org/xwt/js/Parser.java
src/org/xwt/util/Grammar.java

index a4b1650..0336e27 100644 (file)
@@ -219,9 +219,12 @@ public class JS extends org.xwt.util.BalancedTree {
 
     // 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"; }
 
index 66084e0..ee04b7e 100644 (file)
@@ -319,9 +319,9 @@ class Parser extends Lexer implements ByteCodes {
         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) {
@@ -342,7 +342,7 @@ class Parser extends Lexer implements ByteCodes {
             default:     pushBackToken(); return g;
         }
         if (g == null) return parseGrammar(g0);
-        return new Grammar.Juxtaposition(g, g0);
+        return parseGrammar(new Grammar.Juxtaposition(g, g0));
     }
 
     /**
index 678a63a..48018c7 100644 (file)
@@ -14,25 +14,28 @@ public abstract class Grammar extends JS {
         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;