From: <ha...@us...> - 2007-09-09 14:35:51
|
Revision: 8226 http://jmol.svn.sourceforge.net/jmol/?rev=8226&view=rev Author: hansonr Date: 2007-09-09 07:35:42 -0700 (Sun, 09 Sep 2007) Log Message: ----------- 11.3.17 # new feature: Jmol math x = array(a,b,,,,) # # x = array(3,4,5,6) # print x[3] # >> 5 # Modified Paths: -------------- trunk/Jmol/src/org/jmol/viewer/Compiler.java trunk/Jmol/src/org/jmol/viewer/Eval.java trunk/Jmol/src/org/jmol/viewer/Jmol.properties trunk/Jmol/src/org/jmol/viewer/Token.java Modified: trunk/Jmol/src/org/jmol/viewer/Compiler.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Compiler.java 2007-09-09 13:55:52 UTC (rev 8225) +++ trunk/Jmol/src/org/jmol/viewer/Compiler.java 2007-09-09 14:35:42 UTC (rev 8226) @@ -417,7 +417,7 @@ "SET", ident); if (isSetArray) { addTokenToPrefix(token); - token = Token.tokenArray; + token = Token.tokenArraySelector; tok = Token.leftsquare; } } Modified: trunk/Jmol/src/org/jmol/viewer/Eval.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-09-09 13:55:52 UTC (rev 8225) +++ trunk/Jmol/src/org/jmol/viewer/Eval.java 2007-09-09 14:35:42 UTC (rev 8226) @@ -9967,7 +9967,7 @@ //} //} else if (xPt == 0 && isAssignment) { - addX(Token.tokenArray); + addX(Token.tokenArraySelector); break; } if (!doBitsetSelect()) @@ -10098,7 +10098,7 @@ int pt = xPt; while (xStack[pt--] != op) nParam++; - if (nParam > nParamMax) + if (nParamMax > 0 && nParam > nParamMax) return false; Token[] args = new Token[nParam]; for (int i = nParam; --i >= 0;) @@ -10109,6 +10109,8 @@ return evaluateFind(args); case Token.replace: return evaluateReplace(args); + case Token.array: + return evaluateArray(args); case Token.split: case Token.join: case Token.trim: @@ -10394,6 +10396,15 @@ return addX(sList3); } + private boolean evaluateArray(Token[] args) throws ScriptException { + if (isSyntaxCheck) + return addX(""); + String[] array = new String[args.length]; + for (int i = 0; i < args.length; i++) + array[i] = Token.sValue(args[i]); + return addX(array); + } + private boolean evaluateLoad(Token[] args) throws ScriptException { //System.out.println("eval load"); if (args.length != 1) @@ -10633,7 +10644,7 @@ } Token x2 = getX(); - if (x2 == Token.tokenArray) + if (x2 == Token.tokenArraySelector) return false; //unary: Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2007-09-09 13:55:52 UTC (rev 8225) +++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties 2007-09-09 14:35:42 UTC (rev 8226) @@ -64,8 +64,14 @@ # print a # >> a = "this is not a test" # +# new feature: Jmol math x = array(a,b,,,,) +# +# x = array(3,4,5,6) +# print x[3] +# >> 5 +# -# new feature Jmol math plane(x,y,z,w) function +# new feature: Jmol math plane(x,y,z,w) function # # plane(a,b,c,d) or plane("{x,y,z,w}") # or through three points: Modified: trunk/Jmol/src/org/jmol/viewer/Token.java =================================================================== --- trunk/Jmol/src/org/jmol/viewer/Token.java 2007-09-09 13:55:52 UTC (rev 8225) +++ trunk/Jmol/src/org/jmol/viewer/Token.java 2007-09-09 14:35:42 UTC (rev 8226) @@ -384,7 +384,9 @@ // the only requirement is that these numbers be unique // xxx(a) - + + final static int array = 1 | 0 << 3 | mathfunc; + final static int load = 1 | 1 << 3 | mathfunc | command | negnums; final static int substructure = 2 | 1 << 3 | mathfunc; final static int script = 3 | 1 << 3 | mathfunc | command; @@ -777,7 +779,7 @@ final static Token tokenOr = new Token(opOr, "or"); final static Token tokenComma = new Token(comma, ","); final static Token tokenMinus = new Token(minus, "-"); - final static Token tokenArray = new Token(leftsquare, "["); + final static Token tokenArraySelector = new Token(leftsquare, "["); final static Token tokenExpressionBegin = new Token(expressionBegin, "expressionBegin"); @@ -1171,6 +1173,7 @@ "angle", new Token(angle), "find", new Token(find), "size", new Token(size), + "array", new Token(array), "split", new Token(split), "join", new Token(join), "trim", new Token(trim), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |