sinceLastRepeat = null;
replace = save;
- } else if (trimmed.startsWith("//#switch")) {
+ } else if (trimmed.startsWith("//#switch") || trimmed.startsWith("//#jswitch")) {
+ boolean jswitch = trimmed.startsWith("//#jswitch");
int expStart = trimmed.indexOf('(') +1;
if (expStart < 1) { err.add(new Error("expected ( in #switch")); continue PROCESS; }
int expEnd = trimmed.lastIndexOf(')');
if (expEnd - expStart <= 1) { err.add(new Error("badly formed #switch statement")); continue PROCESS; }
String expr = trimmed.substring(expStart, expEnd);
- out.print("final String ccSwitch"+enumSwitch+" = (String)("+expr+"); ");
+ if(jswitch) {
+ out.print("final org.ibex.js.JS ccSwitchExpr"+enumSwitch+" = " + expr + ";");
+ out.print("if(org.ibex.js.JS.isString(ccSwitchExpr"+enumSwitch+")) {");
+ out.print("final String ccSwitch"+enumSwitch+" = org.ibex.js.JS.toString(ccSwitchExpr"+enumSwitch+");");
+ } else {
+ out.print("final String ccSwitch"+enumSwitch+" = "+expr+"; ");
+ }
out.print("SUCCESS:do { switch(ccSwitch"+enumSwitch+".length()) {\n");
Hashtable[] byLength = new Hashtable[255];
out.print("} "); /* switch */
if (Default != null) out.print(" " + Default);
out.print(" } while(false);\n"); /* OUTER */
+ if(jswitch) out.print("}");
enumSwitch++;
} else {