41 |
|
|
42 |
|
#ifndef SELECTION_SELECTIONCOMPILER_HPP |
43 |
|
#define SELECTION_SELECTIONCOMPILER_HPP |
44 |
+ |
#include <iostream> |
45 |
|
#include <string> |
46 |
|
#include <vector> |
47 |
+ |
|
48 |
+ |
#include "selection/Token.hpp" |
49 |
+ |
#include "selection/TokenMap.hpp" |
50 |
|
namespace oopse { |
51 |
|
|
52 |
|
|
66 |
|
|
67 |
|
clausePrimitive ::= clauseComparator | |
68 |
|
clauseWithin | |
69 |
< |
clauseChemObject | |
69 |
> |
clauseName | |
70 |
|
none | all | |
71 |
|
( clauseOr ) |
72 |
|
|
75 |
|
clauseWithin ::= WITHIN ( clauseDistance , expression ) |
76 |
|
|
77 |
|
clauseDistance ::= integer | decimal |
78 |
< |
|
79 |
< |
clauseChemObject::= {clauseMolecule} | {clauseStuntDouble} |
78 |
> |
|
79 |
> |
clauseName::= *|string{.string{.string}} |
80 |
|
|
77 |
– |
clauseMolecule ::= {clauseMolName} | {clauseMolIndex} |
81 |
|
|
79 |
– |
clauseMolName ::= molname clauseName |
80 |
– |
|
81 |
– |
clauseName::= *|string |
82 |
– |
|
83 |
– |
clauseMolIndex ::= molindex clauseIndex |
84 |
– |
|
85 |
– |
clauseIndex ::= integer {- integer } |
86 |
– |
|
87 |
– |
clauseStuntDouble ::= {clauseStuntDoubleName} | {clauseStuntDoubleIndex} |
88 |
– |
|
89 |
– |
clauseStuntDoubleName ::= name clauseName |
90 |
– |
|
91 |
– |
clauseStuntDoubleIndex ::= index clauseIndex |
92 |
– |
|
82 |
|
* </pre> |
83 |
|
*/ |
84 |
|
class SelectionCompiler{ |
113 |
|
|
114 |
|
private: |
115 |
|
|
116 |
< |
bool internalcompile(); |
116 |
> |
bool internalCompile(); |
117 |
|
|
118 |
|
|
119 |
|
bool lookingAtLeadingWhitespace(); |
120 |
< |
bool lookingAtComment(); |
120 |
> |
//bool lookingAtComment(); |
121 |
|
bool lookingAtEndOfLine(); |
122 |
|
bool lookingAtEndOfStatement(); |
123 |
|
bool lookingAtString(); |
124 |
+ |
bool lookingAtDecimal(bool allowNegative); |
125 |
+ |
bool lookingAtInteger(bool allowNegative); |
126 |
+ |
bool lookingAtLookupToken(); |
127 |
+ |
bool lookingAtSpecialString(); |
128 |
|
|
129 |
+ |
std::string getUnescapedStringLiteral(); |
130 |
+ |
int getHexitValue(char ch); |
131 |
|
|
132 |
< |
bool compileCommand(const std::vector<vector>&); |
132 |
> |
bool compileCommand(const std::vector<Token>& ltoken); |
133 |
> |
bool compileExpression(); |
134 |
> |
bool compileExpression(int itoken); |
135 |
|
|
136 |
|
bool clauseOr(); |
137 |
|
bool clauseAnd(); |
139 |
|
bool clausePrimitive(); |
140 |
|
bool clauseWithin(); |
141 |
|
bool clauseComparator(); |
142 |
< |
bool clauseChemObject(); |
143 |
< |
bool clauseMolecule(); |
147 |
< |
bool clauseMolName(); |
148 |
< |
bool clauseMolIndex(); |
149 |
< |
bool clauseName(); |
142 |
> |
bool clauseChemObjName(); |
143 |
> |
bool clauseName(std::string& name); |
144 |
|
bool clauseIndex(); |
145 |
< |
bool clauseStuntDoubleName(); |
146 |
< |
bool clauseStuntDoubleIndex(); |
145 |
> |
Token tokenNext(); |
146 |
> |
boost::any valuePeek(); |
147 |
> |
int tokPeek(); |
148 |
|
|
149 |
+ |
bool addTokenToPostfix(const Token& token); |
150 |
+ |
|
151 |
+ |
|
152 |
|
bool compileError(const std::string& errorMessage) { |
153 |
< |
std::cerr << "SelectionCompiler Error: " << errorMessage << << std::endl; |
153 |
> |
std::cerr << "SelectionCompiler Error: " << errorMessage << std::endl; |
154 |
|
error = true; |
155 |
< |
this.errorMessage = errorMessage; |
155 |
> |
this->errorMessage = errorMessage; |
156 |
|
return false; |
157 |
|
} |
158 |
|
|
189 |
|
} |
190 |
|
|
191 |
|
bool unrecognizedExpressionToken() { |
192 |
< |
return compileError("unrecognized expression token:" + valuePeek()); |
192 |
> |
boost::any tmp = valuePeek(); |
193 |
> |
std::string tokenStr; |
194 |
> |
|
195 |
> |
try { |
196 |
> |
tokenStr = boost::any_cast<std::string>(tmp); |
197 |
> |
} catch(const boost::bad_any_cast &) { |
198 |
> |
return compileError("any_cast error"); |
199 |
> |
} |
200 |
> |
|
201 |
> |
return compileError("unrecognized expression token:" + tokenStr); |
202 |
|
} |
203 |
|
|
204 |
|
bool comparisonOperatorExpected() { |
205 |
|
return compileError("comparison operator expected"); |
206 |
|
} |
207 |
|
|
208 |
< |
bool integerExpected() { |
209 |
< |
return compileError("integer expected"); |
208 |
> |
bool numberExpected() { |
209 |
> |
return compileError("number expected"); |
210 |
|
} |
211 |
|
|
212 |
+ |
bool numberOrKeywordExpected() { |
213 |
+ |
return compileError("number or keyword expected"); |
214 |
+ |
} |
215 |
|
|
216 |
|
std::string filename; |
217 |
|
std::string script; |