fixed bug 440
authoradam <adam@megacz.com>
Mon, 9 Feb 2004 22:46:28 +0000 (22:46 +0000)
committeradam <adam@megacz.com>
Mon, 9 Feb 2004 22:46:28 +0000 (22:46 +0000)
darcs-hash:20040209224628-5007d-58f72a1a89adbb729643f4b2ee9cab1952312e53.gz

Makefile
src/org/ibex/Ibex.java
src/org/ibex/Template.java
src/org/ibex/util/Preprocessor.java

index 19f1e40..4e9dc64 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -260,9 +260,9 @@ dist: compile
 propose-patch:
        @darcs push --and-apply --edit-description -o .darcspatch -T patches@xwt.org http://darcs.ibex.org/ibex/
        @(echo "To: patches@xwt.org";\
-        SUB=`grep -A2 New.patches .darcspatch | tail -n 1 | cut -b 2-`;\
+        SUB=`grep -A10000 New.patches .darcspatch | grep '^\\[' | cut -b 2- | tr \\\n , | sed s_,_,\ _g | sed "s_, *\\$$__"`;\
         echo "Subject: $$SUB";\
         echo;\
-        cat .darcspatch) | cat > /tmp/foo #/usr/sbin/sendmail -bm -f $(USER)@xwt.org patches@xwt.org;
+        cat .darcspatch) | /usr/sbin/sendmail -bm -f $(USER)@xwt.org patches@xwt.org;
        @rm .darcspatch 
 
index ba80775..6a2a58a 100644 (file)
@@ -335,7 +335,7 @@ public final class Ibex extends JS.Cloneable {
         public JSScope getStatic() {
             try {
                 // FIXME background?
-                if (t == null) t = Template.buildTemplate(parentkey + ".ixt", Stream.getInputStream(parent.get(parentkey + ".ixt")), ibex);
+                if (t == null) t = Template.buildTemplate(parentkey + ".t", Stream.getInputStream(parent.get(parentkey + ".t")), ibex);
                 return t.staticScope;
             } catch (Exception e) {
                 Log.error(this, e);
@@ -347,6 +347,7 @@ public final class Ibex extends JS.Cloneable {
             if (nargs == 9999) return t;
             if (nargs != 1) throw new JSExn("FIXME can only call with one arg");
             getStatic();
+            if (t == null) throw new JSExn("No such template " + parentkey);
             t.apply((Box)a);
             return a;
         }
index ec47e7c..aa190b3 100644 (file)
@@ -32,7 +32,7 @@ public class Template {
     private Vec children = new Vec();   ///< during XML parsing, this holds the list of currently-parsed children; null otherwise
     private JS script = null;           ///< the script on this node
     Template prev;
-    JSScope staticScope = null;   ///< the scope in which the static block is executed
+    JSScope staticScope = null;         ///< the scope in which the static block is executed
 
 
     // Only used during parsing /////////////////////////////////////////////////////////////////
@@ -138,7 +138,7 @@ public class Template {
        String sourceName;
         private int state = STATE_INITIAL;
         private static final int STATE_INITIAL = 0;
-        private static final int STATE_IN_Ibex_NODE = 1;
+        private static final int STATE_IN_ROOT_NODE = 1;
         private static final int STATE_IN_TEMPLATE_NODE = 2; 
         private static final int STATE_IN_META_NODE = 3;
 
@@ -173,9 +173,9 @@ public class Template {
                         throw new XML.Exn("root element was not <ibex>", XML.Exn.SCHEMA, getLine(), getCol());
                     if (c.getAttrLen() != 0)
                         throw new XML.Exn("root element must not have attributes", XML.Exn.SCHEMA, getLine(), getCol());
-                    state = STATE_IN_Ibex_NODE;
+                    state = STATE_IN_ROOT_NODE;
                     return;
-                case STATE_IN_Ibex_NODE:
+                case STATE_IN_ROOT_NODE:
                     if ("meta".equals(c.getPrefix())) { state = STATE_IN_META_NODE; meta = 0; return; }
                     state = STATE_IN_TEMPLATE_NODE;
                     t = (t == null) ? new Template(ibex) : new Template(t, getLine());
@@ -186,11 +186,12 @@ public class Template {
                     break;
             }
 
-            if (!("ui".equals(c.getPrefix()) && "box".equals(c.getLocalName()))) {
+            if (!(/* "ui".equals(c.getPrefix()) && */ "box".equals(c.getLocalName()))) {
                 String tagname = (c.getUri().equals("") ? "" : (c.getUri() + ".")) + c.getLocalName();
                 // GROSS hack
                 try {
                     t.prev = (Template)t.ibex.resolveString(tagname, false).call(null, null, null, null, 9999);
+                    if (t.prev == null) throw new JSExn("template " + tagname + " not found");
                 } catch (Exception e) {
                     Log.error(Template.class, e);
                 }
@@ -267,11 +268,11 @@ public class Template {
 
         public void endElement(XML.Element c) throws XML.Exn, IOException {
             switch(state) {
-                case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_Ibex_NODE; return;
-                case STATE_IN_Ibex_NODE: return;
+                case STATE_IN_META_NODE: if (meta-- < 0) state = STATE_IN_ROOT_NODE; return;
+                case STATE_IN_ROOT_NODE: return;
                 case STATE_IN_TEMPLATE_NODE: {
                     if (t.content != null) { t.script = parseScript(t.content, t.content_start); t.content = null; }
-                    if (nodeStack.size() == 0) { state = STATE_IN_Ibex_NODE; return; }
+                    if (nodeStack.size() == 0) { state = STATE_IN_ROOT_NODE; return; }
                     Template oldt = t;
                     t = (Template)nodeStack.lastElement();
                     nodeStack.setSize(nodeStack.size() - 1);
@@ -293,7 +294,7 @@ public class Template {
                     }
                     t.content.append(ch, start, length);
                     return;
-                case STATE_IN_Ibex_NODE:
+                case STATE_IN_ROOT_NODE:
                     if (static_content == null) {
                         static_content_start = getLine();
                         static_content = new StringBuffer();
index 0b6e1ef..54c2b1c 100644 (file)
@@ -56,6 +56,7 @@ public class Preprocessor {
 
     private int enumSwitch = 0; // number appended to variable used in switch implementation
 
+   
     public Preprocessor(Reader reader, Writer writer) {
         setReader(reader);
         setWriter(writer);
@@ -121,7 +122,7 @@ PROCESS:
                     String val = trimmed.substring(keyEnd).trim();
                     replace.put(key, val);
                 }
-                out.println(); // preserve line numbers
+                out.print("\n"); // preserve line numbers
                 
             } else if (trimmed.startsWith("//#repeat ")) {
                 trimmed = trimmed.substring(9);
@@ -129,7 +130,7 @@ PROCESS:
                     String s2 = in.readLine().trim();
                     if (s2.startsWith("//")) s2 = s2.substring(2).trim();
                     trimmed = trimmed.substring(0, trimmed.length() - 1) + " " + s2;
-                    out.println();  // preserve line numbers
+                    out.print("\n");  // preserve line numbers
                 }
                 StringTokenizer st = new StringTokenizer(trimmed, " ");
                 repeatreplace = (Hashtable)replace.clone();
@@ -140,13 +141,13 @@ PROCESS:
                     repeatreplace.put(key, val);
                 }
                 sinceLastRepeat = new Vector();
-                out.println(); // preserve line numbers
+                out.print("\n"); // preserve line numbers
 
             } else if (trimmed.startsWith("//#end")) {
                 if (sinceLastRepeat == null) { err.add(new Warning("#end orphaned")); continue PROCESS; }
                 Hashtable save = replace;
                 replace = repeatreplace;
-                out.println();
+                out.print("\n");
                 for(int i=0; i<sinceLastRepeat.size() - 1; i++) out.print(processLine((String)sinceLastRepeat.elementAt(i), true));
                 sinceLastRepeat = null;
                 replace = save;
@@ -159,8 +160,8 @@ PROCESS:
                 if (expEnd - expStart <= 1) { err.add(new Error("badly formed #switch statement")); continue PROCESS; }
                 String expr = trimmed.substring(expStart, expEnd);
 
-                out.println("final String ccSwitch"+enumSwitch+" = (String)("+expr+");");
-                out.println("SUCCESS:do { switch(ccSwitch"+enumSwitch+".length()) {");
+                out.print("final String ccSwitch"+enumSwitch+" = (String)("+expr+");  ");
+                out.print("SUCCESS:do { switch(ccSwitch"+enumSwitch+".length()) {\n");
 
                 Hashtable[] byLength = new Hashtable[255];
                 String key = null;
@@ -190,7 +191,7 @@ PROCESS:
 
                     if (key != null) {
                         Hashtable hash = byLength[key.length()];
-                        hash.put(key, (String)hash.get(key) + processLine(trimmed, false) + "\n");
+                        hash.put(key, (String)hash.get(key) + processLine(trimmed, false).replaceAll("//[^\"]*$", ""));
                     } else {
                         out.print(processLine(trimmed, false));
                     }
@@ -198,13 +199,13 @@ PROCESS:
 
                 for(int i=0; i<255; i++) {
                     if (byLength[i] == null) continue;
-                    out.println("case " + i + ": { switch(ccSwitch"+enumSwitch+".charAt(0)) {");
+                    out.print("case " + i + ": { switch(ccSwitch"+enumSwitch+".charAt(0)) {\n");
                     buildTrie("", byLength[i]);
-                    out.println("}; break; }");
+                    out.print("}; break; }\n");
                 }
-                out.println("} //switch");
-                if (Default != null) out.println(Default);
-                out.println("} while(false); //OUTER");
+                out.print("} /* switch */ ");
+                if (Default != null) out.print("\n" + Default);
+                out.print(" } while(false); //OUTER\n");
                 enumSwitch++;
 
             } else {
@@ -227,18 +228,18 @@ PROCESS:
             if (!((String)keys.elementAt(i)).startsWith(prefix)) continue;
             String prefixPlusOne = ((String)keys.elementAt(i)).substring(0, prefix.length() + 1);
             if (i<keys.size()-1 && prefixPlusOne.equals((((String)keys.elementAt(i + 1)).substring(0, prefix.length() + 1)))) {
-                out.println("case \'" + prefixPlusOne.charAt(prefixPlusOne.length() - 1) + "\': {");
-                out.println("switch(ccSwitch"+enumSwitch+".charAt(" + (prefix.length()+1) + ")) {");
+                out.print("case \'" + prefixPlusOne.charAt(prefixPlusOne.length() - 1) + "\': { ");
+                out.print("switch(ccSwitch"+enumSwitch+".charAt(" + (prefix.length()+1) + ")) { ");
                 buildTrie(prefixPlusOne, cases);
-                out.println("} break; }");
+                out.print("} break; } ");
                 while(i<keys.size() && prefixPlusOne.equals(((String)keys.elementAt(i)).substring(0, prefix.length() + 1))) i++;
                 if (i<keys.size()) { i--; continue; }
             } else {
-                out.println("case \'" + prefixPlusOne.charAt(prefixPlusOne.length() - 1) + "\':");
+                out.print("case \'" + prefixPlusOne.charAt(prefixPlusOne.length() - 1) + "\': ");
                 String code = (String)cases.get(keys.elementAt(i));
                 code = code.substring(0, code.length() - 1);
                 String key = (String)keys.elementAt(i);
-                out.println("if (\""+key+"\".equals(ccSwitch"+enumSwitch+")) { if (true) do { " + code + " } while(false); break SUCCESS; } break; ");
+                out.print("if (\""+key+"\".equals(ccSwitch"+enumSwitch+")) { if (true) do { " + code + " } while(false); break SUCCESS; } break;  ");
             }
         }
     }