From: <ha...@us...> - 2014-02-23 20:55:54
|
Revision: 19376 http://sourceforge.net/p/jmol/code/19376 Author: hansonr Date: 2014-02-23 20:55:47 +0000 (Sun, 23 Feb 2014) Log Message: ----------- ___JmolVersion="14.1.11_2014.02.23" new feature: associative array alternative ".." syntax -- same as JavaScript and Java, but ".." instead of "." -- for example: a["test"] == a..test Modified Paths: -------------- trunk/Jmol/src/org/jmol/script/SV.java trunk/Jmol/src/org/jmol/script/ScriptCompiler.java trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java trunk/Jmol/src/org/jmol/script/T.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties Modified: trunk/Jmol/src/org/jmol/script/SV.java =================================================================== --- trunk/Jmol/src/org/jmol/script/SV.java 2014-02-22 23:46:17 UTC (rev 19375) +++ trunk/Jmol/src/org/jmol/script/SV.java 2014-02-23 20:55:47 UTC (rev 19376) @@ -163,6 +163,8 @@ : sizeOf(selectItemTok(x, Integer.MIN_VALUE)); case hash: return ((Map<String, SV>) x.value).size(); + case context: + return ((ScriptContext) x.value).getFullMap().size(); default: return 0; } @@ -512,6 +514,7 @@ switch (x == null ? nada : x.tok) { case on: case hash: + case context: return true; case off: return false; @@ -1045,6 +1048,7 @@ return PT.esc((String) value); case varray: case hash: + case context: SB sb = new SB(); Map<Object,Boolean>map = new Hashtable<Object,Boolean>(); sValueArray(sb, this, map, 0, true); @@ -1197,6 +1201,7 @@ case bitset: case hash: case varray: + case context: return x1.equals(x2); case point3f: return (((P3) x1.value).distance((P3) x2.value) < 0.000001); @@ -1393,7 +1398,8 @@ case hash: return ((Map<String, SV>) value).get(key); case context: - return ((ScriptContext) value).getVariable(key); + ScriptContext sc = ((ScriptContext) value); + return (key.equals("_path") ? newS(sc.contextPath) : sc.getVariable(key)); } return null; } Modified: trunk/Jmol/src/org/jmol/script/ScriptCompiler.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2014-02-22 23:46:17 UTC (rev 19375) +++ trunk/Jmol/src/org/jmol/script/ScriptCompiler.java 2014-02-23 20:55:47 UTC (rev 19376) @@ -137,6 +137,7 @@ private int tokInitialPlusPlus; private int afterWhite; + private boolean isDotDot; synchronized ScriptContext compile(String filename, String script, boolean isPredefining, boolean isSilent, boolean debugScript, boolean isCheckOnly) { @@ -990,7 +991,7 @@ if (T.tokAttr(tokCommand, T.setparam) && ch == '=' || (isNewSet || isSetBrace) && isOperation) { setCommand(isAndEquals ? T.tokenSet - : ch == '[' && !isSetBrace ? T.tokenSetArray : T.tokenSetProperty); + : ch == '[' && !isSetBrace || ch == '.' && ch2 == '.' ? T.tokenSetArray : T.tokenSetProperty); ltoken.add(0, tokenCommand); cchToken = 1; switch (ch) { @@ -999,7 +1000,13 @@ bracketCount++; return CONTINUE; case '.': - addTokenToPrefix(T.o(T.per, ".")); + if (ch2 == '.') { + addTokenToPrefix(T.o(T.leftsquare, "[")); + cchToken= 2; + isDotDot = true; + return CONTINUE; + } + addTokenToPrefix(T.o(T.per, ".")); return CONTINUE; case '-': case '+': @@ -1246,6 +1253,12 @@ T token; + if (isDotDot) { + addTokenToPrefix(T.o(T.string, ident)); + addTokenToPrefix(T.o(T.rightsquare, "]")); + isDotDot = false; + return CONTINUE; + } if (tokLastMath != 0) tokLastMath = theTok; if (flowContext != null && flowContext.token.tok == T.switchcmd @@ -1358,6 +1371,7 @@ case T.per: if (tokCommand == T.set && parenCount == 0 && bracketCount == 0 && ichToken < setEqualPt) { + // a[3]. ltoken.add(1, T.tokenExpressionBegin); addTokenToPrefix(T.tokenExpressionEnd); ltoken.set(0, T.tokenSetProperty); @@ -1425,6 +1439,11 @@ bracketCount--; if (bracketCount < 0) return ERROR(ERROR_tokenUnexpected, "]"); + break; + case T.perper: + isDotDot = true; + addTokenToPrefix(T.o(T.leftsquare, "[")); + return CONTINUE; } return OK; } @@ -2640,7 +2659,10 @@ case ')': case ']': case '}': + break; case '.': + if (charAt(ichT) == '.') + ++ichT; break; case '@': case '{': Modified: trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2014-02-22 23:46:17 UTC (rev 19375) +++ trunk/Jmol/src/org/jmol/script/ScriptEvaluator.java 2014-02-23 20:55:47 UTC (rev 19376) @@ -1089,12 +1089,18 @@ i++; break out; case T.comma: // ignore commas - if (!ignoreComma && nParen == 0 && nSquare == 0) { + if (!ignoreComma && nParen == 0 && nSquare == 0) break out; - } if (!rpn.addOp(theToken)) invArg(); break; + case T.perper: + if (tokAt(i + 1) == T.nada) + invArg(); + rpn.addOp(T.o(T.leftsquare, "[")); + rpn.addXStr(optParameterAsString(++i)); + rpn.addOp(T.o(T.rightsquare, "]")); + continue; case T.per: SV token = getBitsetPropertySelector(i + 1, false); if (token == null) @@ -2517,6 +2523,8 @@ fixed[j] = SV.newV(v instanceof M4 ? T.matrix4f : T.matrix3f, v); } else if (v instanceof Map<?, ?>) { fixed[j] = SV.newV(T.hash, v); + } else if (v instanceof ScriptContext) { + fixed[j] = SV.newV(T.hash, ((ScriptContext)v).getFullMap()); } else if (v instanceof List<?>) { List<SV> sv = (List<SV>) v; BS bs = null; Modified: trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java =================================================================== --- trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2014-02-22 23:46:17 UTC (rev 19375) +++ trunk/Jmol/src/org/jmol/script/ScriptMathProcessor.java 2014-02-23 20:55:47 UTC (rev 19376) @@ -863,9 +863,10 @@ case T.type: return addXStr(typeOf(x2)); case T.keys: - if (x2.tok != T.hash) + if (x2.tok != T.hash && x2.tok != T.context) return addXStr(""); - Set<String> keyset = ((Map<String, SV>) x2.value).keySet(); + Set<String> keyset = ((Map<String, SV>) (x2.tok == T.hash ? x2.value + : ((ScriptContext) x2.value).getFullMap())).keySet(); String[] keys = keyset.toArray(new String[keyset.size()]); Arrays.sort(keys); return addXAS(keys); @@ -1476,6 +1477,7 @@ case T.hash: case T.matrix3f: case T.matrix4f: + case T.context: return T.astrType[tok]; } return "?"; Modified: trunk/Jmol/src/org/jmol/script/T.java =================================================================== --- trunk/Jmol/src/org/jmol/script/T.java 2014-02-22 23:46:17 UTC (rev 19375) +++ trunk/Jmol/src/org/jmol/script/T.java 2014-02-23 20:55:47 UTC (rev 19376) @@ -91,14 +91,15 @@ public final static int matrix4f = 12; // listf "list-float" is specifically for xxx.all.bin, // but it could be developed further - public final static int listf = 13; - final private static int keyword = 14; + public final static int listf = 13; + public final static int context = 14; + final private static int keyword = 15; public final static String[] astrType = { "nada", "identifier", "integer", "decimal", "string", "seqcode", "hash", "array", "point", "point4", "bitset", - "matrix3f", "matrix4f", "listf", "keyword" + "matrix3f", "matrix4f", "listf", "context", "keyword" }; public static boolean tokAttr(int a, int b) { @@ -403,9 +404,10 @@ public final static int expressionEnd = expression | 2; public final static int all = expression | 3; public final static int branch = expression | 4; - public final static int coord = expression | 6; - public final static int dollarsign = expression | 7; - public final static int per = expression | 8; + public final static int coord = expression | 5; + public final static int dollarsign = expression | 6; + public final static int per = expression | 7; + public final static int perper = expression | 8; public final static int isaromatic = expression | 9; public final static int leftbrace = expression | 10; public final static int none = expression | 11; @@ -1127,7 +1129,6 @@ public final static int colorscheme = misc | 64; public final static int command = misc | 66; public final static int commands = misc | 68; - public final static int context = misc | 69; public final static int constraint = misc | 70; public final static int contour = misc | 72; public final static int contourlines = misc | 74; @@ -1547,6 +1548,7 @@ "<>", null, "within", T.t(within), ".", T.t(per), + "..", T.t(perper), "[", T.t(leftsquare), "]", T.t(rightsquare), "{", T.t(leftbrace), Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2014-02-22 23:46:17 UTC (rev 19375) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2014-02-23 20:55:47 UTC (rev 19376) @@ -11,8 +11,16 @@ # The quotes above look odd for a parameter file, but they are # important for the JavaScript version of Jmol. -___JmolVersion="14.1.11_2014.02.22" +___JmolVersion="14.1.11_2014.02.23" + +new feature: associative array alternative ".." syntax + -- same as JavaScript and Java, but ".." instead of "." + -- for example: + a["test"] == a..test + +JmolVersion="14.1.11_2014.02.22" + bug fix: {*}.covalent is misleading in that it is a mix of covalent and ionic bonding distances. As such, I have replaced it with data at the Blue Obelisk Data Repository which are from This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |