39 #include "BESTokenizer.h" 40 #include "BESSyntaxUserError.h" 42 BESTokenizer::BESTokenizer() :
43 _counter(-1), _number_tokens(0)
47 BESTokenizer::~BESTokenizer()
65 string error =
"Parse error.";
68 for (
int w = 0; w < _counter + 1; w++)
69 where += tokens[w] +
" ";
70 where +=
"<----HERE IS THE ERROR";
71 error +=
"\n" + where;
73 if (s !=
"") error +=
"\n" + s;
89 return tokens[_counter];
104 if (_counter < 0 || _counter > (
int)_number_tokens - 1) {
108 return tokens[_counter];
123 if (_counter == -1) {
127 if (_counter >= (
int) (_number_tokens - 1)) {
131 return tokens[++_counter];
162 size_t len = strlen(p);
164 bool passing_raw =
false;
165 bool escaped =
false;
167 for (
unsigned int j = 0; j < len; j++) {
169 if (!escaped && p[j] ==
'\"') {
185 passing_raw = !passing_raw;
188 else if (passing_raw) {
190 if (!escaped && p[j] ==
'\\') {
196 if (escaped) escaped =
false;
201 if ((p[j] ==
' ') || (p[j] ==
'\n') || (p[j] == 0x0D) || (p[j] == 0x0A)) {
207 else if ((p[j] ==
',') || (p[j] ==
';')) {
214 tokens.push_back(
",");
217 tokens.push_back(
";");
226 if (s !=
"") tokens.push_back(s);
227 _number_tokens = tokens.size();
228 if (passing_raw)
parse_error(
"Unclose quote found.(\")");
229 if (_number_tokens < 1)
parse_error(
"Unknown command: '" + (
string) p + (
string)
"'");
230 if (tokens[_number_tokens - 1] !=
";")
parse_error(
"The request must be terminated by a semicolon (;)");
255 string::size_type where = s.rfind(
".constraint=", s.size());
256 if (where == string::npos) {
257 where = s.rfind(
".attributes=", s.size());
258 if (where == string::npos) {
268 string valid = s.substr(where, s.size());
269 if ((valid !=
".constraint=") && (valid !=
".attributes=")) {
270 string err = (string)
"Invalid container property " + valid +
" for container " + s.substr(0, where)
271 +
". constraint expressions and attribute lists " +
"must be wrapped in quotes";
274 return s.substr(0, where);
290 if ((s[0] !=
'"') || (s[s.size() - 1] !=
'"')) {
291 parse_error(
"item " + s +
" must be enclosed by quotes");
293 return s.substr(1, s.size() - 2);
306 tokens_citerator i = tokens.begin();
307 tokens_citerator ie = tokens.end();
308 for (; i != ie; i++) {
309 cout <<
"\"" << (*i) <<
"\"" << endl;
321 strm << BESIndent::LMarg <<
"BESTokenizer::dump - (" << (
void *)
this <<
")" << endl;
323 tokens_citerator i = tokens.begin();
324 tokens_citerator ie = tokens.end();
325 for (; i != ie; i++) {
326 strm << BESIndent::LMarg <<
"\"" << (*i) <<
"\"" << endl;
328 BESIndent::UnIndent();
string & get_next_token()
returns the next token from the token list
error thrown if there is a user syntax error in the request or any other user error
string & get_first_token()
returns the first token from the token list
string remove_quotes(const string &s)
removes quotes from a quoted token
virtual void dump(ostream &strm) const
dumps information about this object
string parse_container_name(const string &s, unsigned int &type)
parses a container name for constraint and attributes
void parse_error(const string &s="")
throws an exception giving the tokens up to the point of the problem
void tokenize(const char *p)
tokenize the BES request/command string
string & get_current_token()
returns the current token from the token list
void dump_tokens()
dump the tokens that have been tokenized in the order in which they are parsed.