From: <ha...@us...> - 2014-03-17 12:34:30
|
Revision: 19456 http://sourceforge.net/p/jmol/code/19456 Author: hansonr Date: 2014-03-17 12:34:24 +0000 (Mon, 17 Mar 2014) Log Message: ----------- ___JmolVersion="14.1.12_2014.03.17" bug fix: write XYZ broken by changes to the way arrays are shown with the PRINT command bug fix: x = adfjladj(3) crashes Jmol bug fix: x[0] = "tst" "here" "now" should cause script exception Modified Paths: -------------- trunk/Jmol/src/org/jmol/script/SV.java trunk/Jmol/src/org/jmol/script/ScriptExpr.java trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java Modified: trunk/Jmol/src/org/jmol/script/SV.java =================================================================== --- trunk/Jmol/src/org/jmol/script/SV.java 2014-03-17 03:20:21 UTC (rev 19455) +++ trunk/Jmol/src/org/jmol/script/SV.java 2014-03-17 12:34:24 UTC (rev 19456) @@ -617,7 +617,7 @@ if (x.value instanceof String) return (String) x.value; // just the command sb = new SB(); - sValueArray(sb, (SV) x, "", "", false); + sValueArray(sb, (SV) x, "", "", false, true); return sb.toString(); case string: String s = (String) x.value; @@ -642,7 +642,7 @@ } private static void sValueArray(SB sb, SV vx, String path, String tabs, - boolean isEscaped) { + boolean isEscaped, boolean isRaw) { switch (vx.tok) { case hash: case context: @@ -655,17 +655,19 @@ } path += thiskey; if (vx.tok == varray) { - sb.append(isEscaped ? "[ " : tabs + "\t[\n"); + if (!isRaw) + sb.append(isEscaped ? "[ " : tabs + "[\n"); List<SV> sx = vx.getList(); for (int i = 0; i < sx.size(); i++) { if (isEscaped && i > 0) sb.append(","); SV sv = sx.get(i); - sValueArray(sb, sv, path, tabs + "\t", isEscaped); + sValueArray(sb, sv, path, tabs + "\t", isEscaped, tabs.length() == 0 && !isEscaped && isRawType(sv.tok)); if (!isEscaped) sb.append("\n"); } - sb.append(isEscaped ? " ]" : tabs + "\t]"); + if (!isRaw) + sb.append(isEscaped ? " ]" : tabs + "]"); } else { Map<String, SV> ht = (vx.tok == context ? ((ScriptContext) vx.value) .getFullMap() : vx.getMap()); @@ -673,7 +675,7 @@ } break; default: - if (!isEscaped) + if (!isRaw && !isEscaped) sb.append(tabs); sb.append(isEscaped ? vx.escape() : sValue(vx)); } @@ -689,30 +691,22 @@ for (int i = 0; i < keys.length; i++) { String key = keys[i]; sb.append(sep).append(PT.esc(key)).appendC(':'); - sValueArray(sb, ht.get(key), path, tabs+"\t", true); + sValueArray(sb, ht.get(key), path, tabs+"\t", true, false); sep = ","; } sb.append(" }"); return; } sb.append(tabs).append("{\n"); + tabs += "\t"; for (int i = 0; i < keys.length; i++) { sb.append(tabs); String key = keys[i]; sb.append(key).append("\t:"); SB sb2 = new SB(); SV v = ht.get(key); - isEscaped = false; - switch (v.tok) { - case T.string: - case T.decimal: - case T.integer: - case T.point3f: - case T.point4f: - case T.bitset: - isEscaped = true; - } - sValueArray(sb2, v, path, (v.tok == hash ? tabs + "\t" : tabs), isEscaped); + isEscaped = isRawType(v.tok); + sValueArray(sb2, v, path, tabs, isEscaped, false); String value = sb2.toString(); if (isEscaped) sb.append("\t"); @@ -720,9 +714,24 @@ sb.append("\n"); sb.append(value).append("\n"); } - sb.append(tabs).append("}"); + sb.append(tabs.substring(1)).append("}"); } + private static boolean isRawType(int tok) { + switch (tok) { + case T.string: + case T.decimal: + case T.integer: + case T.point3f: + case T.point4f: + case T.bitset: + case T.on: + case T.off: + return true; + } + return false; + } + public static P3 ptValue(SV x) { switch (x.tok) { case point3f: @@ -1059,7 +1068,7 @@ case hash: case context: SB sb = new SB(); - sValueArray(sb, this, "", "", true); + sValueArray(sb, this, "", "", true, false); return sb.toString(); default: return sValue(this); Modified: trunk/Jmol/src/org/jmol/script/ScriptExpr.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptExpr.java 2014-03-17 03:20:21 UTC (rev 19455) +++ trunk/Jmol/src/org/jmol/script/ScriptExpr.java 2014-03-17 12:34:24 UTC (rev 19456) @@ -111,7 +111,7 @@ * variables * @param localVar * x or y in above for(), select() examples - * @param isAssignment TODO + * @param isSpecialAssignment TODO * @return either a vector or a value, caller's choice. * @throws ScriptException * errors are thrown directly to the Eval error system. @@ -119,7 +119,7 @@ protected Object parameterExpression(int pt, int ptMax, String key, boolean ignoreComma, boolean asVector, int ptAtom, boolean isArrayItem, - Map<String, SV> localVars, String localVar, boolean isAssignment) + Map<String, SV> localVars, String localVar, boolean isSpecialAssignment) throws ScriptException { /* @@ -144,11 +144,11 @@ int nSquare = 0; int nParen = 0; boolean topLevel = true; - ScriptMathProcessor rpn = new ScriptMathProcessor(this, isAssignment, isArrayItem, asVector, - false, false); + ScriptMathProcessor rpn = new ScriptMathProcessor(this, isSpecialAssignment, isArrayItem, asVector, + false, false, key); if (ptMax < pt) ptMax = slen; - int ptEq = (isAssignment ? 0 : 1); + int ptEq = (isSpecialAssignment ? 0 : 1); out: for (int i = pt; i < ptMax; i++) { v = null; int tok = getToken(i).tok; @@ -177,8 +177,8 @@ break out; if (tok == T.rightbrace) invArg(); - if (isAssignment && nSquare == 1 && tokAt(i + 1) == T.opEQ) - isAssignment = rpn.endAssignment(); + if (isSpecialAssignment && nSquare == 1 && tokAt(i + 1) == T.opEQ) + isSpecialAssignment = rpn.endAssignment(); } switch (tok) { @@ -414,8 +414,8 @@ break; case T.perper: case T.per: - if (isAssignment && topLevel && tokAt(i + 2) == T.opEQ) - isAssignment = rpn.endAssignment(); + if (isSpecialAssignment && topLevel && tokAt(i + 2) == T.opEQ) + isSpecialAssignment = rpn.endAssignment(); if (ptEq == 0 && topLevel) { switch (tokAt(i + 1)) { case T.nada: @@ -636,7 +636,7 @@ st = code; } ScriptMathProcessor rpn = new ScriptMathProcessor(this, false, false, - false, mustBeBitSet, allowUnderflow); + false, mustBeBitSet, allowUnderflow, null); Object val; int comparisonValue = Integer.MAX_VALUE; boolean refreshed = false; @@ -1942,8 +1942,9 @@ SV t = (settingData ? null : getContextVariableAsVariable(key)); - // determine whether this is some sort of special assignment - // of a known variable + // determine whether this is some sort of + // special assignment of a known variable + if (isSet && !isExpression) { // pt will be 1 unless... switch (tokAt(2)) { Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2014-03-17 03:20:21 UTC (rev 19455) +++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2014-03-17 12:34:24 UTC (rev 19456) @@ -92,15 +92,17 @@ private int ptid = 0; private int ptx = Integer.MAX_VALUE; private int pto = Integer.MAX_VALUE; - private boolean isAssignment; + private boolean isSpecialAssignment; private boolean doSelections = true; private boolean assignLeft; private boolean allowUnderflow; + private boolean isAssignment; - ScriptMathProcessor(ScriptExpr eval, boolean isAssignment, boolean isArrayItem, - boolean asVector, boolean asBitSet, boolean allowUnderflow) { + ScriptMathProcessor(ScriptExpr eval, boolean isSpecialAssignment, boolean isArrayItem, + boolean asVector, boolean asBitSet, boolean allowUnderflow, String key) { this.eval = eval; - this.isAssignment = assignLeft = isAssignment; + this.isSpecialAssignment = assignLeft = isSpecialAssignment; + this.isAssignment = (isSpecialAssignment || key != null); this.viewer = eval.viewer; this.debugHigh = eval.debugHigh; this.chk = wasSyntaxCheck = eval.chk; @@ -126,11 +128,11 @@ if (isOK) { if (asVector) { // check for y = x x or y = x + ; - if (isAssignment && (xPt > 0 && oPt < 0 || oPt >= 0 && oStack[oPt] != null)) + if (isAssignment && (xPt > 0 && oPt < 0 || oPt >= 0 && (xPt > 1 || oStack[oPt] != null))) eval.invArg(); List<SV> result = new List<SV>(); for (int i = 0; i <= xPt; i++) - result.addLast(isAssignment ? xStack[i] : SV.selectItemVar(xStack[i])); + result.addLast(isSpecialAssignment ? xStack[i] : SV.selectItemVar(xStack[i])); if (lastAssignedString != null) { result.remove(0); result.add(0, lastAssignedString); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |