2004/01/08 05:02:19
[org.ibex.core.git] / src / org / xwt / js / Interpreter.java
index ae8dc1f..32bf03e 100644 (file)
@@ -356,6 +356,28 @@ class Interpreter implements ByteCodes, Tokens {
             case THROW:
                 throw new JSExn(stack.pop());
 
+            case MAKE_GRAMMAR: {
+                final Grammar r = (Grammar)arg;
+                final JSScope final_scope = scope;
+                Grammar r2 = new Grammar() {
+                        public int match(String s, int start, Hash v, JSScope scope) throws JSExn {
+                            return r.match(s, start, v, final_scope);
+                        }
+                        public int matchAndWrite(String s, int start, Hash v, JSScope scope, String key) throws JSExn {
+                            return r.matchAndWrite(s, start, v, final_scope, key);
+                        }
+                        public Object call(Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn {
+                            Hash v = new Hash();
+                            r.matchAndWrite((String)a0, 0, v, final_scope, "foo");
+                            return v.get("foo");
+                        }
+                    };
+                Object obj = stack.pop();
+                if (obj != null && obj instanceof Grammar) r2 = new Grammar.Alternative((Grammar)obj, r2);
+                stack.push(r2);
+                break;
+            }
+
             case ASSIGN_SUB: case ASSIGN_ADD: {
                 Object val = stack.pop();
                 Object key = stack.pop();