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 /////////////////////////////////////////////////////////////////
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;
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());
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);
}
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);
}
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();
private int enumSwitch = 0; // number appended to variable used in switch implementation
+
public Preprocessor(Reader reader, Writer writer) {
setReader(reader);
setWriter(writer);
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);
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();
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;
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;
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));
}
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 {
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; ");
}
}
}