| 50 |
|
namespace oopse { |
| 51 |
|
|
| 52 |
|
|
| 53 |
< |
/** |
| 54 |
< |
* @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp" |
| 55 |
< |
* @brief compile a selection script to tokens |
| 56 |
< |
* @todo document |
| 57 |
< |
* <pre> |
| 53 |
> |
/** |
| 54 |
> |
* @class SelectionCompiler SelectionCompiler.hpp "selection/SelectionCompiler.hpp" |
| 55 |
> |
* @brief compile a selection script to tokens |
| 56 |
> |
* @todo document |
| 57 |
> |
* <pre> |
| 58 |
|
|
| 59 |
< |
expression :: = clauseOr |
| 59 |
> |
expression :: = clauseOr |
| 60 |
|
|
| 61 |
< |
clauseOr ::= clauseAnd {OR clauseAnd}* |
| 61 |
> |
clauseOr ::= clauseAnd {OR clauseAnd}* |
| 62 |
|
|
| 63 |
< |
clauseAnd ::= clauseNot {AND clauseNot}* |
| 63 |
> |
clauseAnd ::= clauseNot {AND clauseNot}* |
| 64 |
|
|
| 65 |
< |
clauseNot ::= NOT clauseNot | clausePrimitive |
| 65 |
> |
clauseNot ::= NOT clauseNot | clausePrimitive |
| 66 |
|
|
| 67 |
< |
clausePrimitive ::= clauseComparator | |
| 68 |
< |
clauseWithin | |
| 69 |
< |
clauseName | |
| 70 |
< |
none | all | |
| 71 |
< |
( clauseOr ) |
| 67 |
> |
clausePrimitive ::= clauseComparator | |
| 68 |
> |
clauseWithin | |
| 69 |
> |
clauseName | |
| 70 |
> |
none | all | |
| 71 |
> |
( clauseOr ) |
| 72 |
|
|
| 73 |
< |
clauseComparator ::= atomproperty comparatorop integer |
| 73 |
> |
clauseComparator ::= atomproperty comparatorop integer |
| 74 |
|
|
| 75 |
< |
clauseWithin ::= WITHIN ( clauseDistance , expression ) |
| 75 |
> |
clauseWithin ::= WITHIN ( clauseDistance , expression ) |
| 76 |
|
|
| 77 |
< |
clauseDistance ::= integer | decimal |
| 77 |
> |
clauseDistance ::= integer | decimal |
| 78 |
|
|
| 79 |
< |
clauseName::= *|string{.string{.string}} |
| 79 |
> |
clauseName::= *|string{.string{.string}} |
| 80 |
|
|
| 81 |
|
|
| 82 |
< |
* </pre> |
| 83 |
< |
*/ |
| 84 |
< |
class SelectionCompiler{ |
| 85 |
< |
public: |
| 86 |
< |
bool compile(const std::string& filename, const std::string& script ); |
| 82 |
> |
* </pre> |
| 83 |
> |
*/ |
| 84 |
> |
class SelectionCompiler{ |
| 85 |
> |
public: |
| 86 |
> |
bool compile(const std::string& filename, const std::string& script ); |
| 87 |
|
|
| 88 |
|
|
| 89 |
< |
std::vector<int> getLineNumbers() { |
| 90 |
< |
return lineNumbers; |
| 91 |
< |
} |
| 89 |
> |
std::vector<int> getLineNumbers() { |
| 90 |
> |
return lineNumbers; |
| 91 |
> |
} |
| 92 |
|
|
| 93 |
< |
std::vector<int> getLineIndices() { |
| 94 |
< |
return lineIndices; |
| 95 |
< |
} |
| 93 |
> |
std::vector<int> getLineIndices() { |
| 94 |
> |
return lineIndices; |
| 95 |
> |
} |
| 96 |
|
|
| 97 |
< |
std::vector<std::vector<Token> > getAatokenCompiled() { |
| 98 |
< |
return aatokenCompiled; |
| 99 |
< |
} |
| 97 |
> |
std::vector<std::vector<Token> > getAatokenCompiled() { |
| 98 |
> |
return aatokenCompiled; |
| 99 |
> |
} |
| 100 |
|
|
| 101 |
< |
std::string getErrorMessage() { |
| 102 |
< |
std::string strError = errorMessage; |
| 103 |
< |
strError += " : " + errorLine + "\n"; |
| 101 |
> |
std::string getErrorMessage() { |
| 102 |
> |
std::string strError = errorMessage; |
| 103 |
> |
strError += " : " + errorLine + "\n"; |
| 104 |
|
|
| 105 |
< |
if (!filename.empty()) { |
| 106 |
< |
strError += filename; |
| 107 |
< |
} |
| 105 |
> |
if (!filename.empty()) { |
| 106 |
> |
strError += filename; |
| 107 |
> |
} |
| 108 |
|
|
| 109 |
< |
return strError; |
| 110 |
< |
} |
| 109 |
> |
return strError; |
| 110 |
> |
} |
| 111 |
|
|
| 112 |
|
|
| 113 |
< |
private: |
| 113 |
> |
private: |
| 114 |
|
|
| 115 |
< |
bool internalCompile(); |
| 115 |
> |
bool internalCompile(); |
| 116 |
|
|
| 117 |
|
|
| 118 |
< |
bool lookingAtLeadingWhitespace(); |
| 119 |
< |
//bool lookingAtComment(); |
| 120 |
< |
bool lookingAtEndOfLine(); |
| 121 |
< |
bool lookingAtEndOfStatement(); |
| 122 |
< |
bool lookingAtString(); |
| 123 |
< |
bool lookingAtDecimal(bool allowNegative); |
| 124 |
< |
bool lookingAtInteger(bool allowNegative); |
| 125 |
< |
bool lookingAtLookupToken(); |
| 126 |
< |
bool lookingAtSpecialString(); |
| 118 |
> |
bool lookingAtLeadingWhitespace(); |
| 119 |
> |
//bool lookingAtComment(); |
| 120 |
> |
bool lookingAtEndOfLine(); |
| 121 |
> |
bool lookingAtEndOfStatement(); |
| 122 |
> |
bool lookingAtString(); |
| 123 |
> |
bool lookingAtDecimal(bool allowNegative); |
| 124 |
> |
bool lookingAtInteger(bool allowNegative); |
| 125 |
> |
bool lookingAtLookupToken(); |
| 126 |
> |
bool lookingAtSpecialString(); |
| 127 |
|
|
| 128 |
< |
std::string getUnescapedStringLiteral(); |
| 129 |
< |
int getHexitValue(char ch); |
| 128 |
> |
std::string getUnescapedStringLiteral(); |
| 129 |
> |
int getHexitValue(char ch); |
| 130 |
|
|
| 131 |
< |
bool compileCommand(const std::vector<Token>& ltoken); |
| 132 |
< |
bool compileExpression(); |
| 133 |
< |
bool compileExpression(int itoken); |
| 131 |
> |
bool compileCommand(const std::vector<Token>& ltoken); |
| 132 |
> |
bool compileExpression(); |
| 133 |
> |
bool compileExpression(int itoken); |
| 134 |
|
|
| 135 |
< |
bool clauseOr(); |
| 136 |
< |
bool clauseAnd(); |
| 137 |
< |
bool clauseNot(); |
| 138 |
< |
bool clausePrimitive(); |
| 139 |
< |
bool clauseWithin(); |
| 140 |
< |
bool clauseComparator(); |
| 141 |
< |
bool clauseChemObjName(); |
| 142 |
< |
bool clauseIndex(); |
| 143 |
< |
Token tokenNext(); |
| 144 |
< |
boost::any valuePeek(); |
| 145 |
< |
int tokPeek(); |
| 135 |
> |
bool clauseOr(); |
| 136 |
> |
bool clauseAnd(); |
| 137 |
> |
bool clauseNot(); |
| 138 |
> |
bool clausePrimitive(); |
| 139 |
> |
bool clauseWithin(); |
| 140 |
> |
bool clauseComparator(); |
| 141 |
> |
bool clauseChemObjName(); |
| 142 |
> |
bool clauseIndex(); |
| 143 |
> |
Token tokenNext(); |
| 144 |
> |
boost::any valuePeek(); |
| 145 |
> |
int tokPeek(); |
| 146 |
|
|
| 147 |
< |
bool addTokenToPostfix(const Token& token); |
| 148 |
< |
bool isNameValid(const std::string& name); |
| 147 |
> |
bool addTokenToPostfix(const Token& token); |
| 148 |
> |
bool isNameValid(const std::string& name); |
| 149 |
|
|
| 150 |
< |
bool compileError(const std::string& errorMsg) { |
| 151 |
< |
std::cerr << "SelectionCompiler Error: " << errorMsg << std::endl; |
| 152 |
< |
error = true; |
| 153 |
< |
this->errorMessage = errorMsg; |
| 154 |
< |
return false; |
| 155 |
< |
} |
| 150 |
> |
bool compileError(const std::string& errorMsg) { |
| 151 |
> |
std::cerr << "SelectionCompiler Error: " << errorMsg << std::endl; |
| 152 |
> |
error = true; |
| 153 |
> |
this->errorMessage = errorMsg; |
| 154 |
> |
return false; |
| 155 |
> |
} |
| 156 |
|
|
| 157 |
< |
bool commandExpected() { |
| 158 |
< |
return compileError("command expected"); |
| 159 |
< |
} |
| 157 |
> |
bool commandExpected() { |
| 158 |
> |
return compileError("command expected"); |
| 159 |
> |
} |
| 160 |
|
|
| 161 |
< |
bool invalidExpressionToken(const std::string& ident) { |
| 162 |
< |
return compileError("invalid expression token:" + ident); |
| 163 |
< |
} |
| 161 |
> |
bool invalidExpressionToken(const std::string& ident) { |
| 162 |
> |
return compileError("invalid expression token:" + ident); |
| 163 |
> |
} |
| 164 |
|
|
| 165 |
< |
bool unrecognizedToken() { |
| 166 |
< |
return compileError("unrecognized token"); |
| 167 |
< |
} |
| 165 |
> |
bool unrecognizedToken() { |
| 166 |
> |
return compileError("unrecognized token"); |
| 167 |
> |
} |
| 168 |
|
|
| 169 |
< |
bool badArgumentCount() { |
| 170 |
< |
return compileError("bad argument count"); |
| 171 |
< |
} |
| 169 |
> |
bool badArgumentCount() { |
| 170 |
> |
return compileError("bad argument count"); |
| 171 |
> |
} |
| 172 |
|
|
| 173 |
< |
bool endOfExpressionExpected() { |
| 174 |
< |
return compileError("end of expression expected"); |
| 175 |
< |
} |
| 173 |
> |
bool endOfExpressionExpected() { |
| 174 |
> |
return compileError("end of expression expected"); |
| 175 |
> |
} |
| 176 |
|
|
| 177 |
< |
bool leftParenthesisExpected() { |
| 178 |
< |
return compileError("left parenthesis expected"); |
| 179 |
< |
} |
| 177 |
> |
bool leftParenthesisExpected() { |
| 178 |
> |
return compileError("left parenthesis expected"); |
| 179 |
> |
} |
| 180 |
|
|
| 181 |
< |
bool rightParenthesisExpected() { |
| 182 |
< |
return compileError("right parenthesis expected"); |
| 183 |
< |
} |
| 181 |
> |
bool rightParenthesisExpected() { |
| 182 |
> |
return compileError("right parenthesis expected"); |
| 183 |
> |
} |
| 184 |
|
|
| 185 |
< |
bool commaExpected() { |
| 186 |
< |
return compileError("comma expected"); |
| 187 |
< |
} |
| 185 |
> |
bool commaExpected() { |
| 186 |
> |
return compileError("comma expected"); |
| 187 |
> |
} |
| 188 |
|
|
| 189 |
< |
bool unrecognizedExpressionToken() { |
| 190 |
< |
boost::any tmp = valuePeek(); |
| 191 |
< |
std::string tokenStr; |
| 189 |
> |
bool unrecognizedExpressionToken() { |
| 190 |
> |
boost::any tmp = valuePeek(); |
| 191 |
> |
std::string tokenStr; |
| 192 |
|
|
| 193 |
< |
try { |
| 194 |
< |
tokenStr = boost::any_cast<std::string>(tmp); |
| 195 |
< |
} catch(const boost::bad_any_cast &) { |
| 196 |
< |
return compileError("any_cast error"); |
| 197 |
< |
} |
| 193 |
> |
try { |
| 194 |
> |
tokenStr = boost::any_cast<std::string>(tmp); |
| 195 |
> |
} catch(const boost::bad_any_cast &) { |
| 196 |
> |
return compileError("any_cast error"); |
| 197 |
> |
} |
| 198 |
|
|
| 199 |
< |
return compileError("unrecognized expression token:" + tokenStr); |
| 200 |
< |
} |
| 199 |
> |
return compileError("unrecognized expression token:" + tokenStr); |
| 200 |
> |
} |
| 201 |
|
|
| 202 |
< |
bool comparisonOperatorExpected() { |
| 203 |
< |
return compileError("comparison operator expected"); |
| 204 |
< |
} |
| 202 |
> |
bool comparisonOperatorExpected() { |
| 203 |
> |
return compileError("comparison operator expected"); |
| 204 |
> |
} |
| 205 |
|
|
| 206 |
< |
bool numberExpected() { |
| 207 |
< |
return compileError("number expected"); |
| 208 |
< |
} |
| 206 |
> |
bool numberExpected() { |
| 207 |
> |
return compileError("number expected"); |
| 208 |
> |
} |
| 209 |
|
|
| 210 |
< |
bool numberOrKeywordExpected() { |
| 211 |
< |
return compileError("number or keyword expected"); |
| 212 |
< |
} |
| 210 |
> |
bool numberOrKeywordExpected() { |
| 211 |
> |
return compileError("number or keyword expected"); |
| 212 |
> |
} |
| 213 |
|
|
| 214 |
< |
std::string filename; |
| 215 |
< |
std::string script; |
| 214 |
> |
std::string filename; |
| 215 |
> |
std::string script; |
| 216 |
|
|
| 217 |
< |
std::vector<int> lineNumbers; |
| 218 |
< |
std::vector<int> lineIndices; |
| 219 |
< |
std::vector<std::vector<Token> >aatokenCompiled; |
| 217 |
> |
std::vector<int> lineNumbers; |
| 218 |
> |
std::vector<int> lineIndices; |
| 219 |
> |
std::vector<std::vector<Token> >aatokenCompiled; |
| 220 |
|
|
| 221 |
< |
bool error; |
| 222 |
< |
std::string errorMessage; |
| 223 |
< |
std::string errorLine; |
| 221 |
> |
bool error; |
| 222 |
> |
std::string errorMessage; |
| 223 |
> |
std::string errorLine; |
| 224 |
|
|
| 225 |
< |
int cchScript; |
| 226 |
< |
short lineCurrent; |
| 225 |
> |
int cchScript; |
| 226 |
> |
short lineCurrent; |
| 227 |
|
|
| 228 |
< |
int ichToken; |
| 229 |
< |
int cchToken; |
| 230 |
< |
std::vector<Token> atokenCommand; |
| 228 |
> |
int ichToken; |
| 229 |
> |
int cchToken; |
| 230 |
> |
std::vector<Token> atokenCommand; |
| 231 |
|
|
| 232 |
< |
int ichCurrentCommand; |
| 232 |
> |
int ichCurrentCommand; |
| 233 |
|
|
| 234 |
< |
std::vector<Token> ltokenPostfix; |
| 235 |
< |
std::vector<Token> atokenInfix; |
| 236 |
< |
int itokenInfix; |
| 234 |
> |
std::vector<Token> ltokenPostfix; |
| 235 |
> |
std::vector<Token> atokenInfix; |
| 236 |
> |
int itokenInfix; |
| 237 |
|
|
| 238 |
< |
//std::vector<Token> compiledTokens_; |
| 239 |
< |
}; |
| 238 |
> |
//std::vector<Token> compiledTokens_; |
| 239 |
> |
}; |
| 240 |
|
|
| 241 |
|
} |
| 242 |
|
#endif |