41#include "BESTokenizer.h"
42#include "BESSyntaxUserError.h"
44BESTokenizer::BESTokenizer() :
45 _counter(-1), _number_tokens(0)
49BESTokenizer::~BESTokenizer()
67 string error =
"Parse error.";
70 for (
int w = 0; w < _counter + 1; w++)
71 where += tokens[w] +
" ";
72 where +=
"<----HERE IS THE ERROR";
73 error +=
"\n" + where;
75 if (s !=
"") error +=
"\n" + s;
91 return tokens[_counter];
106 if (_counter < 0 || _counter > (
int)_number_tokens - 1) {
110 return tokens[_counter];
125 if (_counter == -1) {
129 if (_counter >= (
int) (_number_tokens - 1)) {
133 return tokens[++_counter];
164 size_t len = strlen(p);
166 bool passing_raw =
false;
167 bool escaped =
false;
169 for (
unsigned int j = 0; j < len; j++) {
171 if (!escaped && p[j] ==
'\"') {
187 passing_raw = !passing_raw;
190 else if (passing_raw) {
192 if (!escaped && p[j] ==
'\\') {
198 if (escaped) escaped =
false;
203 if ((p[j] ==
' ') || (p[j] ==
'\n') || (p[j] == 0x0D) || (p[j] == 0x0A)) {
209 else if ((p[j] ==
',') || (p[j] ==
';')) {
216 tokens.push_back(
",");
219 tokens.push_back(
";");
228 if (s !=
"") tokens.push_back(s);
229 _number_tokens = tokens.size();
230 if (passing_raw)
parse_error(
"Unclose quote found.(\")");
231 if (_number_tokens < 1)
parse_error(
"Unknown command: '" + (
string) p + (
string)
"'");
232 if (tokens[_number_tokens - 1] !=
";")
parse_error(
"The request must be terminated by a semicolon (;)");
257 string::size_type where = s.rfind(
".constraint=", s.size());
258 if (where == string::npos) {
259 where = s.rfind(
".attributes=", s.size());
260 if (where == string::npos) {
270 string valid = s.substr(where, s.size());
271 if ((valid !=
".constraint=") && (valid !=
".attributes=")) {
272 string err = (string)
"Invalid container property " + valid +
" for container " + s.substr(0, where)
273 +
". constraint expressions and attribute lists " +
"must be wrapped in quotes";
276 return s.substr(0, where);
292 if ((s[0] !=
'"') || (s[s.size() - 1] !=
'"')) {
293 parse_error(
"item " + s +
" must be enclosed by quotes");
295 return s.substr(1, s.size() - 2);
308 tokens_citerator i = tokens.begin();
309 tokens_citerator ie = tokens.end();
310 for (; i != ie; i++) {
311 cout <<
"\"" << (*i) <<
"\"" << endl;
323 strm << BESIndent::LMarg <<
"BESTokenizer::dump - (" << (
void *)
this <<
")" << endl;
325 tokens_citerator i = tokens.begin();
326 tokens_citerator ie = tokens.end();
327 for (; i != ie; i++) {
328 strm << BESIndent::LMarg <<
"\"" << (*i) <<
"\"" << endl;
330 BESIndent::UnIndent();
error thrown if there is a user syntax error in the request or any other user error
void parse_error(const std::string &s="")
throws an exception giving the tokens up to the point of the problem
void dump_tokens()
dump the tokens that have been tokenized in the order in which they are parsed.
void tokenize(const char *p)
tokenize the BES request/command string
std::string remove_quotes(const std::string &s)
removes quotes from a quoted token
std::string parse_container_name(const std::string &s, unsigned int &type)
parses a container name for constraint and attributes
virtual void dump(std::ostream &strm) const
dumps information about this object
std::string & get_current_token()
returns the current token from the token list
std::string & get_first_token()
returns the first token from the token list
std::string & get_next_token()
returns the next token from the token list