
{ name = "new" sub_name = "SUBTITLE" values = { 1, 2, 3; } input_values = { 1, 2, 3; 5, 5, 6 10, 12, 3} type = input intval = 100 } Can some one help me to write the parser for the above format? I am trying something like below and this doesn’t seem to work for me. template <typename Iterator> struct keys_and_values : qi::grammar<Iterator, mapDef()> { keys_and_values() : keys_and_values::base_type(query) { using namespace qi; query = '{' >> *lit(' ') >> pair >> *(lit(' ') >> *lit(' ') >> pair) >> *lit(' ') >> '}'; pair = key >> -(*lit(' ') >> "=" >> *lit(' ') >> value); key = +char_("a-zA-Z0-9_") ; value = +char_("a-zA-Z0-9") | lexeme[('{' >> +char_("\"@+*.( , ) $ a-zA-Z0-9_ -") >> '}')] | lexeme[('"' >> +char_("\"@+*.( , ) $ a-zA-Z0-9_ -") >> '"')]; } qi::rule<Iterator, mapDef()> query; qi::rule<Iterator, std::pair<std::string, std::string>()> pair; qi::rule<Iterator, std::string()> key, value; }; Any help would be highly appriciated. Regards, UJ

{ name = "new" sub_name = "SUBTITLE" values = { 1, 2, 3; } input_values = { 1, 2, 3; 5, 5, 6 10, 12, 3} type = input intval = 100 }
What is mapDef, i.e what resulting attribute type do you want to get? Anyway, you don't have to skip wihtespeaces in your grammar, it's up to skipper to do this. Besides, note that operator "|" has boost::variant as its attribute (i.e. (+char_("abcd") | int_) would result in variant<stirng, int>) and is usually useful when you want to select the resulting type based on the input.

Igore, On 02/03/14 1:41 pm, "Igor R" <boost.lists@gmail.com> wrote:
{ name = "new" sub_name = "SUBTITLE" values = { 1, 2, 3; } input_values = { 1, 2, 3; 5, 5, 6 10, 12, 3} type = input intval = 100 }
Where mapdef is :: typedef std::vector<std::pair<std::string,std::string>>mapDef; I am looking to store key vs values.. means [ignoring \n, \t and spaces] Name-³new² Values- 1,2,3 input_values-1, 2, 3; 5, 5, 6;10, 12, 3 Can you please let me know what is the best way to write the parser? Regards, UJ

{ name = "new" sub_name = "SUBTITLE" values = { 1, 2, 3; } input_values = { 1, 2, 3; 5, 5, 6 10, 12, 3} type = input intval = 100 }
Where mapdef is :: typedef std::vector<std::pair<std::string,std::string>>mapDef;
I am looking to store key vs values.. means [ignoring \n, \t and spaces] Name-³new² Values- 1,2,3 input_values-1, 2, 3; 5, 5, 6;10, 12, 3
I still don't quite realise what you mean. For the above specific example, how would you store every key/value in vector<pair<string, string>>? Please, fill the following: int main() { vector<pair<string, string>> output; output.push_back(make_pair(?, ?)); }

Igore, On 02/03/14 6:52 pm, "Igor R" <boost.lists@gmail.com> wrote:
{ name = "new" sub_name = "SUBTITLE" values = { 1, 2, 3; } input_values = { 1, 2, 3; 5, 5, 6 ; 10, 12, 3} type = input intval = 100 }
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Equal is the separator and the string left is key and the right is value. [key and value both storing as strings] push_back(name,²new²) push_back(sub_name,²SUBTITLE²) push_back(values,"1,2,3²) push_back(input_values,²1,2,3;5,5,6;10,12,3²) Regards, UJ

On Sun, 02 Mar 2014 15:51:40 +0100, Uthpal Urubail <uthpal.urubail@altair.com> wrote:
I am looking to store key vs values.. means [ignoring \n, \t and spaces] ... Equal is the separator and the string left is key and the right is value. [key and value both storing as strings] push_back(name,²new²) push_back(sub_name,²SUBTITLE²)
push_back(values,"1,2,3²)
push_back(input_values,²1,2,3;5,5,6;10,12,3²)
I guess, if you strip \n and spaces, the terms 'left' and 'right' of = sign become not so unambiguous. Do you separate key-value pairs by some sign? Do " have some special meaning? Just define your syntax clearly for yourself and writing the parser should not be a problem then. Regards, Slava
participants (3)
-
Igor R
-
Slava
-
Uthpal Urubail