Revision: 20790 http://sourceforge.net/p/jmol/code/20790 Author: hansonr Date: 2015-09-22 13:52:29 +0000 (Tue, 22 Sep 2015) Log Message: ----------- Jmol.___JmolVersion="14.3.16_2015.09.22"
bug fix: for(var x in ...) does not respect "var" Modified Paths: -------------- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java trunk/Jmol/src/org/jmol/script/ScriptEval.java trunk/Jmol/src/org/jmol/script/ScriptExpr.java trunk/Jmol/src/org/jmol/script/ScriptParam.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/script/ScriptCompiler.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2015-09-22 12:17:07 UTC (rev 20789) +++ trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2015-09-22 13:52:29 UTC (rev 20790) @@ -431,7 +431,7 @@ private boolean isLineContinuation(int ichT, boolean checkMathop) { boolean isEscaped = (ichT + 2 < cchScript && script.charAt(ichT) == '\\' - && nCharNewLine(ichT + 1) > 0 || checkMathop + && nCharNewLine(ichT + 1) > 0 || !isShowScriptOutput && checkMathop && lookingAtMathContinuation(ichT)); if (isEscaped) lineCurrent++; Modified: trunk/Jmol/src/org/jmol/script/ScriptEval.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEval.java 2015-09-22 12:17:07 UTC (rev 20789) +++ trunk/Jmol/src/org/jmol/script/ScriptEval.java 2015-09-22 13:52:29 UTC (rev 20790) @@ -1078,7 +1078,7 @@ dispatchCommands(false, true, false); //JavaScript will not return here after DELAY or after what??? } - SV v = (getReturn ? getContextVariableAsVariable("_retval") : null); + SV v = (getReturn ? getContextVariableAsVariable("_retval", false) : null); popContext(false, false); return v; } @@ -1119,7 +1119,7 @@ if (pt < 0) { // if pt is a backward reference // this is a break within a try{...} block - getContextVariableAsVariable("_breakval").intValue = -pt; + getContextVariableAsVariable("_breakval", false).intValue = -pt; pcEnd = pc; return; } @@ -3454,8 +3454,12 @@ // for (;;;); // for (var x in {...}) { xxxxx } // for (var x in y) { xxxx } + boolean isLocal = false; for (int i = 1, nSkip = 0; i < slen && j < 2; i++) { switch (tok = tokAt(i)) { + case T.var: + isLocal = true; + break; case T.semicolon: if (nSkip > 0) nSkip--; @@ -3539,7 +3543,17 @@ if (isOK) if (tok == T.in) { // start of FOR (i in x) block or FOR (i from x) - forVar = getForVar(key); + forVar = getContextVariableAsVariable(key, isLocal); + if (forVar == null && !isLocal) + forVar = vwr.g.getOrSetNewVariable(key, false); + if (forVar == null) { + if (key.startsWith("_")) + invArg(); + if (isLocal) + contextVariables.put(key.toLowerCase(), forVar = SV.newI(0)); + else + forVar = vwr.g.getOrSetNewVariable(key, true); + } if (inTok == T.integer) { // for (i from [0 31]) forVar.tok = T.integer; @@ -3563,7 +3577,7 @@ forVars[1] = forVal; } else { if (T.tokAttr(tokAt(j), T.misc) - || (forVal = getContextVariableAsVariable(key)) != null) { + || (forVal = getContextVariableAsVariable(key, false)) != null) { if (!isMinusMinus && getToken(++j).tok != T.opEQ) invArg(); if (isMinusMinus) @@ -5599,7 +5613,7 @@ private void cmdReturn(SV tv) throws ScriptException { if (chk) return; - SV t = getContextVariableAsVariable("_retval"); + SV t = getContextVariableAsVariable("_retval", false); if (t != null) { SV v = (tv != null || slen == 1 ? null : parameterExpressionToken(1)); if (tv == null) @@ -6911,7 +6925,7 @@ // var xxxx = xxx can supercede set xxxx - boolean isContextVariable = (!justShow && !isJmolSet && getContextVariableAsVariable(key) != null); + boolean isContextVariable = (!justShow && !isJmolSet && getContextVariableAsVariable(key, false) != null); if (!justShow && !isContextVariable) { @@ -8509,19 +8523,6 @@ color2, nColors)); } - private SV getForVar(String key) throws ScriptException { - SV t = getContextVariableAsVariable(key); - if (t == null) { - if (key.startsWith("_")) - invArg(); - if (key.indexOf("/") >= 0) - contextVariables.put(key.toLowerCase(), t = SV.newI(0)); - else - t = vwr.g.getOrSetNewVariable(key, true); - } - return t; - } - public String getFullPathName() throws ScriptException { String filename = (!chk || isCmdLine_C_Option ? vwr .fm.getFullPathName(true) : "test.xyz"); Modified: trunk/Jmol/src/org/jmol/script/ScriptExpr.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptExpr.java 2015-09-22 12:17:07 UTC (rev 20789) +++ trunk/Jmol/src/org/jmol/script/ScriptExpr.java 2015-09-22 13:52:29 UTC (rev 20790) @@ -590,7 +590,7 @@ : null); } if (v == null) - v = getContextVariableAsVariable(name); + v = getContextVariableAsVariable(name, false); else if (ptEq == 0) invArg(); } @@ -2060,7 +2060,7 @@ boolean settingData = key.startsWith("property_"); boolean isThrown = key.equals("thrown_value"); boolean isExpression = (tokAt(1) == T.expressionBegin || tokAt(1) == T.leftparen); - SV t = (settingData ? null : key.length() == 0 ? new SV() : getContextVariableAsVariable(key)); + SV t = (settingData ? null : key.length() == 0 ? new SV() : getContextVariableAsVariable(key, false)); // determine whether this is some sort of // special assignment of a known variable Modified: trunk/Jmol/src/org/jmol/script/ScriptParam.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptParam.java 2015-09-22 12:17:07 UTC (rev 20789) +++ trunk/Jmol/src/org/jmol/script/ScriptParam.java 2015-09-22 13:52:29 UTC (rev 20790) @@ -77,7 +77,7 @@ @SuppressWarnings("unchecked") public Object getParameter(String key, int tokType, boolean nullAsString) { - Object v = getContextVariableAsVariable(key); + Object v = getContextVariableAsVariable(key, false); if (v == null) { if (nullAsString) v = vwr.getP(key); @@ -100,14 +100,14 @@ } protected Object getVarParameter(String var, boolean orReturnName) { - SV v = getContextVariableAsVariable(var); + SV v = getContextVariableAsVariable(var, false); if (v != null) return (orReturnName ? v.asString() : SV.oValue(v)); Object val = vwr.getP(var); return (orReturnName && ("" + val).length() == 0 ? var : val); } - public SV getContextVariableAsVariable(String var) { + public SV getContextVariableAsVariable(String var, boolean isLocal) { if (var.equals("expressionBegin")) return null; if (var.equalsIgnoreCase("_caller")) { @@ -121,7 +121,7 @@ } var = var.toLowerCase(); return (contextVariables != null && contextVariables.containsKey(var) ? contextVariables - .get(var) : thisContext == null ? null : thisContext.getVariable(var)); + .get(var) : isLocal || thisContext == null ? null : thisContext.getVariable(var)); } public String paramAsStr(int i) throws ScriptException { Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-09-22 12:17:07 UTC (rev 20789) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2015-09-22 13:52:29 UTC (rev 20790) @@ -61,23 +61,32 @@ Jmol.___JmolVersion="14.3.16_2015.09.22" +bug fix: for(var x in ...) does not respect "var" + bug fix: x.format("JSON") fails for recursive x -- arrays or associative arrays can be recursive - -- detection of recursion now delivers empty array or associative array + -- detection of recursion during SHOW, x.format("JSON"), and @x (deep copy) + now delivers empty array or associative array + -- example: - $ a = [[1,2],3] - $ a..2 = a - $ print a.format("JSON") - - [ [ 1,2 ],[ [ 1,2 ],[ ] ] ] - - $ a = [b:1] - $ a.b = a - $ print a.format("JSON") - - { "b": { "b": { } } } - + $ a = [[1,2],3] + $ a..2 = a + $ print a.format("JSON") + + [ [ 1,2 ],[ [ 1,2 ],[ ] ] ] + + $ a = [b:1] + $ a.b = a + $ print a.format("JSON") + + { "b": { "b": { } } } + + $ y = @x + $ show y + + y = { "b":{ "b":{ } } } + new feature: x = @a -- deep copy for a = array or associative array -- @a for string variable still gets the value of the variable named by variable a This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ _______________________________________________ Jmol-commits mailing list Jmol-commits@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jmol-commits