|
View:
New views
1 Messages
—
Rating Filter:
Alert me
|
|
|
Need help with variation of "Employee" sampleMy experience with parsing is miniscule. I created a small parser in
spirit 1.8 and was very happy with it. Now I am trying to expand it and move to spirit2. My goal is to create parser in spirit2 that will parse sql-like commands. These commands resemble sql select statement, so I thought I will create a structure (commandselect in the code below) that will have command title ("select") and various structures for parts of the select command. My first command option is a "frequency" option which is an integer followed by the resolution type, for example 10 F2 , or 1 F1. Frequency types are predefined. For testing I am trying to parse a string SELECT 15 F2 Below is my attempt to do the parser using Employee sample from the documentation. It does not compile. Headers for it are taken from Employee sample. Your help will be greatly appreciated. struct frequency { // frequency portion of the command. Example: 30 F1 or 16 F2 or similar int value; int resolution; // resolution is supplied as a string. // After parsing this value should be mapped value from one of allowed frequencies() entry }; BOOST_FUSION_ADAPT_STRUCT ( frequency, (int, value) (int, resolution) ) struct commandselect { // command itself. Example: SELECT 30 F1 or SELECT 16 F2 std::string title; frequency datafrequency; }; BOOST_FUSION_ADAPT_STRUCT( commandselect, (std::string, title) (frequency, datafrequency) ) // this structure holds allowed string values for "frequency" input struct frequencies_ : symbols<char, unsigned> { frequencies_() { add ("F1" , 10) ("F2" , 20); } } frequencies; template <typename Iterator> struct command_parser : grammar<Iterator, commandselect(), space_type> { command_parser() : command_parser::base_type(start) { ruleFrequency %= eps [_val = 0] >> int_ >> frequencies; start %= eps [_val = 0] >> lit("SELECT") >> ruleFrequency; } rule<Iterator, frequency(), space_type> ruleFrequency; rule<Iterator, commandselect(), space_type> start; }; int _tmain(int argc, _TCHAR* argv[]) { typedef std::string::const_iterator iterator_type; typedef command_parser<iterator_type> select_parser; select_parser parser; return 0; } ------------------------------------------------------------------------- This SF.Net email is sponsored by the Moblin Your Move Developer's challenge Build the coolest Linux based applications with Moblin SDK & win great prizes Grand prize is a trip for two to an Open Source event anywhere in the world http://moblin-contest.org/redirect.php?banner_id=100&url=/ _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
| Free Forum Powered by Nabble | Forum Help |