22 #ifndef HYPERTABLE_HSPARSER_H
23 #define HYPERTABLE_HSPARSER_H
27 #ifdef BOOST_SPIRIT_DEBUG
28 #define HS_DEBUG(str) std::cerr << str << std::endl
40 #include <boost/algorithm/string.hpp>
41 #include <boost/spirit/include/classic_confix.hpp>
42 #include <boost/spirit/include/classic_core.hpp>
43 #include <boost/spirit/include/classic_escape_char.hpp>
44 #include <boost/spirit/include/classic_grammar.hpp>
45 #include <boost/spirit/include/classic_symbols.hpp>
50 #include <unordered_map>
57 using namespace boost;
99 lock_mode(0), last_attr_size(0), locate_type(0), recursive(false), as_commands(false) { }
122 : state(state_), command(cmd) { }
124 state.command = command;
133 state.file_name =
String(str, end-str);
141 state.as_commands =
true;
149 state.outfile =
String(str, end-str);
150 trim_if(state.outfile, is_any_of(
"'\""));
158 state.dir_name =
String(str, end-str);
166 state.node_name =
String(str, end-str);
174 state.str =
String(str, end-str);
183 state.help_str =
String(str, end-str);
184 trim(state.help_str);
185 to_lower(state.help_str);
192 : state(state_), open_flag(open_flag_) { }
194 state.open_flag |= open_flag;
202 : state(state_), event_mask(event_mask_) { }
204 state.event_mask |= event_mask;
213 state.last_attr_name =
String(str, end-str);
214 HS_DEBUG(
"set_last_attr_name" << state.last_attr_name);
222 String escaped_double_quote(
"\\\"");
223 String unescaped_double_quote(1,
'"');
224 String escaped_single_quote(
"\\\'");
225 String unescaped_single_quote(
"'");
227 state.last_attr_value =
String(str, end-str);
228 boost::trim_if(state.last_attr_value, is_any_of(
"'\""));
229 boost::algorithm::replace_all(state.last_attr_value, escaped_double_quote, unescaped_double_quote);
230 boost::algorithm::replace_all(state.last_attr_value, escaped_single_quote, unescaped_single_quote);
232 HS_DEBUG(
"set_last_attr_value" << state.last_attr_value);
249 std::unordered_map<String,String>::iterator iter;
251 state.attr_map[state.last_attr_name] = state.last_attr_value;
252 iter = state.attr_map.find(state.last_attr_name);
253 if(iter == state.attr_map.end())
255 "Error: Problem setting attribute");
257 attr.
name = (*iter).first.c_str();
258 attr.
value = (*iter).second.c_str();
260 state.attrs.push_back(attr);
268 : state(state_), lock_mode(lock_mode_) { }
270 state.lock_mode = lock_mode;
278 : state(state_), locate_type(locate_type_) { }
280 state.locate_type = locate_type;
289 state.recursive =
true;
297 template <
typename Scanner>
302 "flags",
"FLAGS",
"attr",
"ATTR",
"event-mask",
"EVENT-MASK";
309 chlit<> SINGLEQUOTE(
'\'');
310 chlit<> DOUBLEQUOTE(
'"');
311 chlit<> QUESTIONMARK(
'?');
320 strlit<> DOUBLEEQUAL(
"==");
330 chlit<> POINTER(
'^');
333 strlit<> DOTDOT(
"..");
334 strlit<> DOUBLEQUESTIONMARK(
"??");
339 typedef inhibit_case<strlit<> > Token;
340 Token C_MKDIR = as_lower_d[
"mkdir"];
341 Token C_MKDIRS = as_lower_d[
"mkdirs"];
342 Token C_DELETE = as_lower_d[
"delete"];
343 Token C_OPEN = as_lower_d[
"open"];
344 Token C_CREATE = as_lower_d[
"create"];
345 Token C_CLOSE = as_lower_d[
"close"];
346 Token C_ATTRSET = as_lower_d[
"attrset"];
347 Token C_ATTRGET = as_lower_d[
"attrget"];
348 Token C_ATTRINCR = as_lower_d[
"attrincr"];
349 Token C_ATTRDEL = as_lower_d[
"attrdel"];
350 Token C_ATTREXISTS = as_lower_d[
"attrexists"];
351 Token C_ATTRLIST = as_lower_d[
"attrlist"];
352 Token C_EXISTS = as_lower_d[
"exists"];
353 Token C_READDIR = as_lower_d[
"readdir"];
354 Token C_READDIRATTR = as_lower_d[
"readdirattr"];
355 Token C_READPATHATTR = as_lower_d[
"readpathattr"];
356 Token C_DUMP = as_lower_d[
"dump"];
357 Token C_LOCK = as_lower_d[
"lock"];
358 Token C_TRYLOCK = as_lower_d[
"trylock"];
359 Token C_RELEASE = as_lower_d[
"release"];
360 Token C_GETSEQ = as_lower_d[
"getseq"];
361 Token C_ECHO = as_lower_d[
"echo"];
362 Token C_HELP = as_lower_d[
"help"];
363 Token C_LOCATE = as_lower_d[
"locate"];
364 Token C_STATUS = as_lower_d[
"status"];
366 Token ESC_HELP = as_lower_d[
"\\h"];
368 Token AS_COMMANDS = as_lower_d[
"as_commands"];
369 Token FLAGS = as_lower_d[
"flags"];
370 Token EVENTMASK = as_lower_d[
"event-mask"];
371 Token O_READ = as_lower_d[
"read"];
372 Token O_WRITE = as_lower_d[
"write"];
373 Token O_LOCK = as_lower_d[
"lock"];
374 Token O_CREATE = as_lower_d[
"create"];
375 Token O_EXCLUSIVE = as_lower_d[
"excl"];
376 Token O_TEMP = as_lower_d[
"temp"];
377 Token O_LOCK_SHARED = as_lower_d[
"lock_shared"];
378 Token O_LOCK_EXCLUSIVE = as_lower_d[
"lock_exclusive"];
379 Token M_ATTR_SET = as_lower_d[
"attr_set"];
380 Token M_ATTR_DEL = as_lower_d[
"attr_del"];
381 Token M_CHILD_NODE_ADDED = as_lower_d[
"child_node_added"];
382 Token M_CHILD_NODE_REMOVED = as_lower_d[
"child_node_removed"];
383 Token M_LOCK_ACQUIRED = as_lower_d[
"lock_acquired"];
384 Token M_LOCK_RELEASED = as_lower_d[
"lock_released"];
385 Token ATTR = as_lower_d[
"attr"];
386 Token L_SHARED = as_lower_d[
"shared"];
387 Token L_EXCLUSIVE = as_lower_d[
"exclusive"];
388 Token R_MASTER = as_lower_d[
"master"];
389 Token R_REPLICAS = as_lower_d[
"replicas"];
390 Token FLAG_R = as_lower_d[
"-r"];
397 = lexeme_d[(+(anychar_p - space_p)) - (keywords)];
400 = lexeme_d[(alpha_p >> *(alnum_p |
'_')) - (keywords)];
403 = single_string_literal
404 | double_string_literal
408 = lexeme_d[*(anychar_p)]
411 single_string_literal
412 = confix_p(SINGLEQUOTE, *lex_escape_ch_p, SINGLEQUOTE);
414 double_string_literal
415 = confix_p(DOUBLEQUOTE, *lex_escape_ch_p, DOUBLEQUOTE);
464 >> !(FLAGS >> EQUAL >> open_flag_value)
465 >> !(EVENTMASK >> EQUAL >> open_event_mask_value)
470 >> FLAGS >> EQUAL >> create_flag_value
471 >> *(one_create_option)
478 = C_ATTRSET >> node_name[
set_node_name(
self.state)] >> attribute;
511 readdirattr_statement
517 readpathattr_statement
530 = C_LOCK >> node_name[
set_node_name(
self.state)] >> lock_mode;
533 = C_TRYLOCK >> node_name[
set_node_name(
self.state)] >> lock_mode;
546 = (C_HELP | ESC_HELP | QUESTIONMARK )
547 >> any_string[
set_help(
self.state)];
551 = C_LOCATE >> locate_type
570 = one_open_flag_value >> *(BITOR >> one_open_flag_value);
572 one_open_event_mask_value
584 open_event_mask_value
585 = one_open_event_mask_value
586 >> *(BITOR >> one_open_event_mask_value);
588 one_create_flag_value
599 = one_create_flag_value >> *(BITOR >> one_create_flag_value);
601 one_create_event_mask_value
609 create_event_mask_value
610 = one_create_event_mask_value
611 >> *(BITOR >> one_create_event_mask_value);
615 (ATTR >> COLON >> attribute)
617 EVENTMASK >> EQUAL >> create_event_mask_value
640 #ifdef BOOST_SPIRIT_DEBUG
641 BOOST_SPIRIT_DEBUG_RULE(identifier);
642 BOOST_SPIRIT_DEBUG_RULE(string_literal);
643 BOOST_SPIRIT_DEBUG_RULE(any_string);
644 BOOST_SPIRIT_DEBUG_RULE(single_string_literal);
645 BOOST_SPIRIT_DEBUG_RULE(double_string_literal);
646 BOOST_SPIRIT_DEBUG_RULE(user_identifier);
647 BOOST_SPIRIT_DEBUG_RULE(statement);
648 BOOST_SPIRIT_DEBUG_RULE(mkdir_statement);
649 BOOST_SPIRIT_DEBUG_RULE(mkdirs_statement);
650 BOOST_SPIRIT_DEBUG_RULE(delete_statement);
651 BOOST_SPIRIT_DEBUG_RULE(open_statement);
652 BOOST_SPIRIT_DEBUG_RULE(create_statement);
653 BOOST_SPIRIT_DEBUG_RULE(close_statement);
654 BOOST_SPIRIT_DEBUG_RULE(help_statement);
655 BOOST_SPIRIT_DEBUG_RULE(locate_statement);
656 BOOST_SPIRIT_DEBUG_RULE(status_statement);
657 BOOST_SPIRIT_DEBUG_RULE(attrset_statement);
658 BOOST_SPIRIT_DEBUG_RULE(attrget_statement);
659 BOOST_SPIRIT_DEBUG_RULE(attrincr_statement);
660 BOOST_SPIRIT_DEBUG_RULE(attrexists_statement);
661 BOOST_SPIRIT_DEBUG_RULE(attrlist_statement);
662 BOOST_SPIRIT_DEBUG_RULE(attrdel_statement);
663 BOOST_SPIRIT_DEBUG_RULE(exists_statement);
664 BOOST_SPIRIT_DEBUG_RULE(readdir_statement);
665 BOOST_SPIRIT_DEBUG_RULE(readdirattr_statement);
666 BOOST_SPIRIT_DEBUG_RULE(readpathattr_statement);
667 BOOST_SPIRIT_DEBUG_RULE(dump_statement);
668 BOOST_SPIRIT_DEBUG_RULE(lock_statement);
669 BOOST_SPIRIT_DEBUG_RULE(trylock_statement);
670 BOOST_SPIRIT_DEBUG_RULE(release_statement);
671 BOOST_SPIRIT_DEBUG_RULE(getseq_statement);
672 BOOST_SPIRIT_DEBUG_RULE(echo_statement);
673 BOOST_SPIRIT_DEBUG_RULE(one_open_flag_value);
674 BOOST_SPIRIT_DEBUG_RULE(open_flag_value);
675 BOOST_SPIRIT_DEBUG_RULE(one_open_event_mask_value);
676 BOOST_SPIRIT_DEBUG_RULE(open_event_mask_value);
677 BOOST_SPIRIT_DEBUG_RULE(one_create_flag_value);
678 BOOST_SPIRIT_DEBUG_RULE(create_flag_value);
679 BOOST_SPIRIT_DEBUG_RULE(one_create_event_mask_value);
680 BOOST_SPIRIT_DEBUG_RULE(create_event_mask_value);
681 BOOST_SPIRIT_DEBUG_RULE(one_create_option);
682 BOOST_SPIRIT_DEBUG_RULE(attribute);
683 BOOST_SPIRIT_DEBUG_RULE(lock_mode);
684 BOOST_SPIRIT_DEBUG_RULE(node_name);
685 BOOST_SPIRIT_DEBUG_RULE(locate_type);
694 rule<Scanner> identifier, string_literal, any_string,
696 statement, mkdir_statement, mkdirs_statement, delete_statement, open_statement,
697 create_statement, close_statement, help_statement, locate_statement,
698 attrset_statement, attrget_statement, attrincr_statement,
699 attrexists_statement, attrdel_statement,
700 attrlist_statement, exists_statement, readdir_statement,
701 readdirattr_statement, readpathattr_statement, dump_statement, lock_statement,
702 trylock_statement, release_statement, getseq_statement, echo_statement,
703 one_open_flag_value, open_flag_value, one_open_event_mask_value,
704 open_event_mask_value, one_create_flag_value, create_flag_value,
705 one_create_event_mask_value, create_event_mask_value,
706 one_create_option, attribute, lock_mode, node_name, locate_type,
715 #endif // HYPERTABLE_HSPARSER_H
void operator()(char const *str, char const *end) const
set_last_attr_name(ParserState &state_)
set_as_commands(ParserState &state_)
void operator()(char const *str, char const *end) const
std::string String
A String is simply a typedef to std::string.
rule< Scanner > user_identifier
set_file_name(ParserState &state_)
Parser(ParserState &state_)
Declarations for Protocol.
Error if create and file exists.
std::vector< Attribute > attrs
void operator()(char const *str, char const *end) const
Po::typed_value< String > * str(String *v=0)
void operator()(char const *, char const *) const
Atomically open and lock file shared, fail if can't.
set_event_mask(ParserState &state_, int event_mask_)
set_command(ParserState &state_, int cmd)
void operator()(char const *str, char const *end) const
void operator()(char const *str, char const *end) const
definition(Parser const &self)
File system utility functions.
set_node_name(ParserState &state_)
const char * name
Name of extended attribute.
Logging routines and macros.
std::unordered_map< String, String > attr_map
void operator()(char const *str, char const *end) const
void operator()(char const *str, char const *end) const
void operator()(char const *str, char const *end) const
void operator()(char const *str, char const *end) const
set_last_attr_size(ParserState &state_)
set_outfile(ParserState &state_)
set_any_string(ParserState &state_)
set_lock_mode(ParserState &state_, int lock_mode_)
set_open_flag(ParserState &state_, int open_flag_)
set_last_attr(ParserState &state_)
set_recursive(ParserState &state)
atomically open and lock file exclusive, fail if can't
const void * value
Pointer to attribute value.
void operator()(char const *str, char const *end) const
Used in conjunction with CREATE to create an ephemeral file.
Holds extended attribute and value.
rule< Scanner > const & start() const
void operator()(char const *str, char const *end) const
void operator()(char const *str, char const *end) const
set_locate_type(ParserState &state_, int locate_type_)
Create file if it does not exist.
set_help(ParserState &state_)
void operator()(char const *str, char const *end) const
void operator()(char const *str, char const *end) const
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
uint32_t value_len
Length of attribute value.
set_dir_name(ParserState &state_)
set_last_attr_value(ParserState &state_)
void operator()(char const *str, char const *end) const
void operator()(char const *str, char const *end) const