| 1 |
< |
/* |
| 1 |
> |
/* |
| 2 |
|
* Copyright (c) 2005 The University of Notre Dame. All Rights Reserved. |
| 3 |
|
* |
| 4 |
|
* The University of Notre Dame grants you ("Licensee") a |
| 42 |
|
#ifndef SELECTION_TOKEN_HPP |
| 43 |
|
#define SELECTION_TOKEN_HPP |
| 44 |
|
|
| 45 |
+ |
#include <map> |
| 46 |
+ |
#include <string> |
| 47 |
+ |
#include <utility> |
| 48 |
+ |
#include "utils/any.hpp" |
| 49 |
|
|
| 50 |
|
namespace oopse { |
| 51 |
|
|
| 52 |
|
|
| 53 |
< |
/** |
| 54 |
< |
* @class Token |
| 55 |
< |
* @todo document |
| 56 |
< |
*/ |
| 57 |
< |
class Token { |
| 53 |
> |
/** |
| 54 |
> |
* @class Token |
| 55 |
> |
* @todo document |
| 56 |
> |
* @note translate from jmol |
| 57 |
> |
*/ |
| 58 |
> |
class Token { |
| 59 |
|
|
| 60 |
< |
public: |
| 60 |
> |
public: |
| 61 |
|
|
| 57 |
– |
int tok; |
| 58 |
– |
int intValue; |
| 59 |
– |
|
| 60 |
– |
const static int nada = 0; |
| 61 |
– |
const static int identifier = 1; |
| 62 |
– |
const static int integer = 2; |
| 63 |
– |
const static int decimal = 3; |
| 64 |
– |
const static int string = 4; |
| 65 |
– |
const static int seqcode = 5; |
| 66 |
– |
const static int unknown = 6; |
| 67 |
– |
const static int keyword = 7; |
| 68 |
– |
const static int whitespace = 8; |
| 69 |
– |
const static int comment = 9; |
| 70 |
– |
const static int endofline = 10; |
| 71 |
– |
const static int endofstatement = 11; |
| 62 |
|
|
| 63 |
< |
const static int command = (1 << 8); |
| 64 |
< |
const static int expressionCommand = (1 << 9); // expression command |
| 65 |
< |
const static int expression = (1 << 15); /// expression term |
| 63 |
> |
int tok; |
| 64 |
> |
boost::any value; |
| 65 |
> |
int intValue; |
| 66 |
|
|
| 67 |
< |
// every property is also valid in an expression context |
| 78 |
< |
const static int atomproperty = (1 << 16) | expression; |
| 79 |
< |
// every predefined is also valid in an expression context |
| 80 |
< |
const static int comparator = (1 << 17) | expression; |
| 81 |
< |
const static int predefinedset = (1 << 18) | expression; |
| 82 |
< |
// generally, the minus sign is used to denote atom ranges |
| 83 |
< |
// this property is used for the few commands which allow negative integers |
| 84 |
< |
const static int negnums = (1 << 21); |
| 85 |
< |
// for some commands the 'set' is optional |
| 67 |
> |
Token() { tok = unknown;} |
| 68 |
|
|
| 69 |
< |
// These are unrelated |
| 70 |
< |
const static int varArgCount = (1 << 4); |
| 71 |
< |
const static int onDefault1 = (1 << 5) | 1; |
| 69 |
> |
Token(const Token& token) { |
| 70 |
> |
*this = token; |
| 71 |
> |
} |
| 72 |
> |
|
| 73 |
> |
Token(int MyTok, int myIntValue, const boost::any& myValue) { |
| 74 |
> |
this->tok = MyTok; |
| 75 |
> |
this->intValue = myIntValue; |
| 76 |
> |
this->value = myValue; |
| 77 |
> |
} |
| 78 |
|
|
| 79 |
< |
// rasmol commands |
| 80 |
< |
const static int define = command | expressionCommand |1; |
| 81 |
< |
const static int select = command |expressionCommand |2 ; |
| 82 |
< |
const static int all = expression | 11 ; |
| 79 |
> |
Token(int myTok, int myIntValue) { |
| 80 |
> |
this->tok = myTok; |
| 81 |
> |
this->intValue = myIntValue; |
| 82 |
> |
} |
| 83 |
|
|
| 84 |
< |
// atom expression operators |
| 85 |
< |
const static int leftparen = expression | 0; |
| 86 |
< |
const static int rightparen = expression | 1; |
| 99 |
< |
const static int hyphen = expression | 2; |
| 100 |
< |
const static int opAnd = expression | 3; |
| 101 |
< |
const static int opOr = expression | 4; |
| 102 |
< |
const static int opNot = expression | 5; |
| 103 |
< |
const static int within = expression | 6; |
| 104 |
< |
const static int plus = expression | 7; |
| 105 |
< |
const static int pick = expression | 8; |
| 106 |
< |
const static int asterisk = expression | 9; |
| 107 |
< |
const static int dot = expression | 11; |
| 108 |
< |
const static int leftsquare = expression | 12; |
| 109 |
< |
const static int rightsquare = expression | 13; |
| 110 |
< |
const static int colon = expression | 14; |
| 111 |
< |
const static int slash = expression | 15; |
| 84 |
> |
Token(int myTok) { |
| 85 |
> |
this->tok = myTok; |
| 86 |
> |
} |
| 87 |
|
|
| 88 |
< |
// miguel 2005 01 01 |
| 89 |
< |
// these are used to demark the beginning and end of expressions |
| 90 |
< |
// they do not exist in the source code, but are emitted by the |
| 91 |
< |
// expression compiler |
| 92 |
< |
const static int expressionBegin = expression | 100; |
| 93 |
< |
const static int expressionEnd = expression | 101; |
| 88 |
> |
Token(int myTok, const boost::any& myValue) { |
| 89 |
> |
this->tok = myTok; |
| 90 |
> |
this->value = myValue; |
| 91 |
> |
} |
| 92 |
> |
|
| 93 |
> |
const static int nada = 0; |
| 94 |
> |
const static int identifier = 1; |
| 95 |
> |
const static int integer = 2; |
| 96 |
> |
const static int decimal = 3; |
| 97 |
> |
const static int string = 4; |
| 98 |
> |
const static int unknown = 5; |
| 99 |
> |
const static int keyword = 6; |
| 100 |
> |
const static int whitespace = 7; |
| 101 |
> |
const static int comment = 8; |
| 102 |
> |
const static int endofline = 9; |
| 103 |
> |
const static int endofstatement = 10; |
| 104 |
|
|
| 105 |
< |
const static int atomno = atomproperty | 0; |
| 106 |
< |
const static int elemno = atomproperty | 1; |
| 107 |
< |
const static int resno = atomproperty | 2; |
| 123 |
< |
const static int radius = atomproperty | 3 ; |
| 124 |
< |
const static int _bondedcount = atomproperty | 6; |
| 125 |
< |
const static int _groupID = atomproperty | 7; |
| 126 |
< |
const static int _atomID = atomproperty | 8; |
| 127 |
< |
const static int _structure = atomproperty | 9; |
| 128 |
< |
const static int occupancy = atomproperty | 10; |
| 129 |
< |
const static int polymerLength= atomproperty | 11; |
| 105 |
> |
const static int command = (1 << 8); |
| 106 |
> |
const static int expressionCommand = (1 << 9); // expression command |
| 107 |
> |
const static int expression = (1 << 10); /// expression term |
| 108 |
|
|
| 109 |
< |
const static int opGT = comparator | 0; |
| 110 |
< |
const static int opGE = comparator | 1; |
| 111 |
< |
const static int opLE = comparator | 2; |
| 134 |
< |
const static int opLT = comparator | 3; |
| 135 |
< |
const static int opEQ = comparator | 4; |
| 136 |
< |
const static int opNE = comparator | 5; |
| 137 |
< |
|
| 138 |
< |
const static int x = expression |2; |
| 139 |
< |
const static int y = expression | 3; |
| 140 |
< |
const static int z = expression | 4; |
| 141 |
< |
const static int none = expression | 5; |
| 142 |
< |
|
| 143 |
< |
|
| 144 |
< |
const static Token tokenAll(all, "all"); |
| 145 |
< |
const static Token tokenAnd(opAnd, "and"); |
| 146 |
< |
const static Token tokenElemno(elemno, "elemno"); |
| 147 |
< |
const static Token tokenExpressionBegin(expressionBegin, "expressionBegin"); |
| 148 |
< |
const static Token tokenExpressionEnd(expressionEnd, "expressionEnd"); |
| 109 |
> |
// generally, the minus sign is used to denote atom ranges |
| 110 |
> |
// this property is used for the few commands which allow negative integers |
| 111 |
> |
const static int negnums = (1 << 11); |
| 112 |
|
|
| 113 |
+ |
//expression involves coordinates which will change every frame, such as withins |
| 114 |
+ |
const static int dynamic = (1 << 12); |
| 115 |
|
|
| 116 |
< |
const static String[] comparatorNames = {">", ">=", "<=", "<", "=", "!="}; |
| 117 |
< |
const static String[] atomPropertyNames = { |
| 118 |
< |
"atomno", "elemno", "resno", "radius", "temperature", "model", |
| 119 |
< |
"_bondedcount", "_groupID", "_atomID", "_structure"}; |
| 116 |
> |
// every property is also valid in an expression context |
| 117 |
> |
const static int atomproperty = (1 << 12) | expression | negnums; |
| 118 |
> |
// every predefined is also valid in an expression context |
| 119 |
> |
const static int comparator = (1 << 13) | expression; |
| 120 |
> |
const static int predefinedset = (1 << 14) | expression; |
| 121 |
> |
const static int embeddedExpression= (1 << 15); // embedded expression |
| 122 |
> |
const static int index = (1 << 16) | expression; |
| 123 |
> |
// rasmol commands |
| 124 |
> |
const static int define = command | expressionCommand |1; |
| 125 |
> |
const static int select = command |expressionCommand |2 ; |
| 126 |
|
|
| 127 |
< |
/* |
| 128 |
< |
Note that the RasMol scripting language is case-insensitive. |
| 158 |
< |
So, the compiler turns all identifiers to lower-case before |
| 159 |
< |
looking up in the hash table. |
| 160 |
< |
Therefore, the left column of this array *must* be lower-case |
| 161 |
< |
*/ |
| 127 |
> |
//predefine |
| 128 |
> |
//const static int selected = predefinedset |0; |
| 129 |
|
|
| 130 |
< |
const static Object[] arrayPairs = { |
| 131 |
< |
// commands |
| 132 |
< |
"define", new Token(define, varArgCount, "define"), |
| 133 |
< |
"select", new Token(select, varArgCount, "select"), |
| 134 |
< |
// atom expressions |
| 135 |
< |
"(", new Token(leftparen, "("), |
| 136 |
< |
")", new Token(rightparen, ")"), |
| 137 |
< |
"-", new Token(hyphen, "-"), |
| 138 |
< |
"and", tokenAnd, |
| 139 |
< |
"&", null, |
| 140 |
< |
"&&", null, |
| 141 |
< |
"or", new Token(opOr, "or"), |
| 142 |
< |
",", null, |
| 143 |
< |
"|", null, |
| 144 |
< |
"||", null, |
| 145 |
< |
"not", new Token(opNot, "not"), |
| 146 |
< |
"!", null, |
| 147 |
< |
"<", new Token(opLT, "<"), |
| 148 |
< |
"<=", new Token(opLE, "<="), |
| 182 |
< |
">=", new Token(opGE, ">="), |
| 183 |
< |
">", new Token(opGT, ">="), |
| 184 |
< |
"==", new Token(opEQ, "=="), |
| 185 |
< |
"=", null, |
| 186 |
< |
"!=", new Token(opNE, "!="), |
| 187 |
< |
"<>", null, |
| 188 |
< |
"/=", null, |
| 189 |
< |
"within", new Token(within, "within"), |
| 190 |
< |
"+", new Token(plus, "+"), |
| 191 |
< |
"pick", new Token(pick, "pick"), |
| 192 |
< |
".", new Token(dot, "."), |
| 193 |
< |
"[", new Token(leftsquare, "["), |
| 194 |
< |
"]", new Token(rightsquare, "]"), |
| 195 |
< |
":", new Token(colon, ":"), |
| 196 |
< |
"/", new Token(slash, "/"), |
| 130 |
> |
// atom expression operators |
| 131 |
> |
const static int leftparen = expression | 0; |
| 132 |
> |
const static int rightparen = expression | 1; |
| 133 |
> |
const static int to = expression | 2; |
| 134 |
> |
const static int opAnd = expression | 3; |
| 135 |
> |
const static int opOr = expression | 4; |
| 136 |
> |
const static int opNot = expression | 5; |
| 137 |
> |
const static int within = expression | dynamic | 6; |
| 138 |
> |
const static int asterisk = expression | 7; |
| 139 |
> |
const static int dot = expression | 8; |
| 140 |
> |
const static int all = expression | 9 ; |
| 141 |
> |
const static int none = expression | 10; |
| 142 |
> |
const static int name = expression | 11; |
| 143 |
> |
// miguel 2005 01 01 |
| 144 |
> |
// these are used to demark the beginning and end of expressions |
| 145 |
> |
// they do not exist in the source code, but are emitted by the |
| 146 |
> |
// expression compiler |
| 147 |
> |
const static int expressionBegin = expression | 100; |
| 148 |
> |
const static int expressionEnd = expression | 101; |
| 149 |
|
|
| 150 |
< |
"atomno", new Token(atomno, "atomno"), |
| 151 |
< |
"elemno", tokenElemno, |
| 152 |
< |
"_e", tokenElemno, |
| 153 |
< |
"resno", new Token(resno, "resno"), |
| 154 |
< |
"temperature", new Token(temperature, "temperature"), |
| 155 |
< |
"relativetemperature", null, |
| 156 |
< |
"_bondedcount", new Token(_bondedcount, "_bondedcount"), |
| 157 |
< |
"_groupID", new Token(_groupID, "_groupID"), |
| 158 |
< |
"_g", null, |
| 207 |
< |
"_atomID", new Token(_atomID, "_atomID"), |
| 208 |
< |
"_a", null, |
| 209 |
< |
"_structure", new Token(_structure, "_structure"), |
| 210 |
< |
"occupancy", new Token(occupancy, "occupancy"), |
| 211 |
< |
"polymerlength",new Token(polymerLength, "polymerlength"), |
| 150 |
> |
const static int mass = atomproperty | 0; |
| 151 |
> |
const static int charge = atomproperty | 1; |
| 152 |
> |
|
| 153 |
> |
const static int opGT = comparator | 0; |
| 154 |
> |
const static int opGE = comparator | 1; |
| 155 |
> |
const static int opLE = comparator | 2; |
| 156 |
> |
const static int opLT = comparator | 3; |
| 157 |
> |
const static int opEQ = comparator | 4; |
| 158 |
> |
const static int opNE = comparator | 5; |
| 159 |
|
|
| 160 |
< |
"x", new Token(x, "x"), |
| 161 |
< |
"y", new Token(y, "y"), |
| 215 |
< |
"z", new Token(z, "z"), |
| 216 |
< |
"*", new Token(asterisk, "*"), |
| 217 |
< |
"all", tokenAll, |
| 218 |
< |
"none", new Token(none, "none"), |
| 219 |
< |
|
| 220 |
< |
}; |
| 160 |
> |
static Token tokenExpressionBegin; |
| 161 |
> |
static Token tokenExpressionEnd; |
| 162 |
|
|
| 163 |
+ |
}; |
| 164 |
|
|
| 223 |
– |
static Hashtable map = new Hashtable(); |
| 224 |
– |
static { |
| 225 |
– |
Token tokenLast = null; |
| 226 |
– |
String stringThis; |
| 227 |
– |
Token tokenThis; |
| 228 |
– |
for (int i = 0; i + 1 < arrayPairs.length; i += 2) { |
| 229 |
– |
stringThis = (String) arrayPairs[i]; |
| 230 |
– |
tokenThis = (Token) arrayPairs[i + 1]; |
| 231 |
– |
if (tokenThis == null) |
| 232 |
– |
tokenThis = tokenLast; |
| 233 |
– |
if (map.get(stringThis) != null) |
| 234 |
– |
System.out.println("duplicate token definition:" + stringThis); |
| 235 |
– |
map.put(stringThis, tokenThis); |
| 236 |
– |
tokenLast = tokenThis; |
| 237 |
– |
} |
| 238 |
– |
} |
| 239 |
– |
|
| 165 |
|
|
| 241 |
– |
}; |
| 242 |
– |
|
| 166 |
|
} |
| 167 |
|
|
| 168 |
< |
#endif |
| 168 |
> |
#endif |