|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
[qi]parsing of recursivly quoted textHi all,
Is it possible to parse the the recursively quoted text using spirit.qi ? I.e. make following test pass: non_quote %= lexeme[*( (char_ - '\"') ) >> -(skip[qouted_word] )]; qouted_word %= '\"'>> skip[non_quote]>>'\"' ; { std::string msg = "\"\"b\"\""; std::string result; std::string::iterator it = msg.begin(); BOOST_CHECK(qi::phrase_parse(it,msg.end(),qouted_word,charset::space,result)); BOOST_CHECK_EQUAL(result,"\"b\""); BOOST_CHECK_EQUAL(std::string(it,msg.end()),""); } What i missed ? The full text is attached. Regards, Anton ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: [qi]parsing of recursivly quoted text2009/11/5 Anton Potapov <balanco@...>:
> Hi all, > Is it possible to parse the the recursively quoted text using spirit.qi ? > > I.e. make following test pass: > > non_quote %= lexeme[*( (char_ - '\"') ) >> -(skip[qouted_word] )]; > qouted_word %= '\"'>> skip[non_quote]>>'\"' ; > > { > std::string msg = "\"\"b\"\""; > std::string result; > std::string::iterator it = msg.begin(); BOOST_CHECK(qi::phrase_parse(it,msg.end(),qouted_word,charset::space,result)); > BOOST_CHECK_EQUAL(result,"\"b\""); > BOOST_CHECK_EQUAL(std::string(it,msg.end()),""); > } > > What i missed ? That is easy to do, but the question is, how would you know when the string starts and stops then? If you know your whole text is a string and you are just stripping quotes there are much easier ways to do that, otherwise, your grammar would become... interesting. That is why C/C++/Python/Lua/Java/etc.../everything has you quote out a quote, like with most \" puts in a literal quote instead of a delimiter. Would be better to have more information on what you are actually trying to do then. ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: [qi]parsing of recursivly quoted text-----Original Message----- From: OvermindDL1 <overminddl1@...> To: Anton Potapov <balanco@...>, Spirit General Mailing List <spirit-general@...> Date: Thu, 5 Nov 2009 05:55:01 -0700 Subject: Re: [Spirit-general] [qi]parsing of recursivly quoted text > 2009/11/5 Anton Potapov <balanco@...>: > > Hi all, > > Is it possible to parse the the recursively quoted text using spirit.qi ? > > > > I.e. ?make following test pass: > > > > ? ? ? ?non_quote ? ? ? %= lexeme[*( (char_ - '\"') ?) >> ?-(skip[qouted_word] )]; > > ? ? ? ?qouted_word ? ? %= ? '\"'>> skip[non_quote]>>'\"' ; > > > > ? ? ? ?{ > > ? ? ? ? ? ? ? ?std::string msg = "\"\"b\"\""; > > ? ? ? ? ? ? ? ?std::string result; > > ? ? ? ? ? ? ? ?std::string::iterator it = msg.begin(); ? ? ? ? ?BOOST_CHECK(qi::phrase_parse(it,msg.end(),qouted_word,charset::space,result)); > > ? ? ? ? ? ? ? ?BOOST_CHECK_EQUAL(result,"\"b\""); > > ? ? ? ? ? ? ? ?BOOST_CHECK_EQUAL(std::string(it,msg.end()),""); > > ? ? ? ?} > > > > What i missed ? > > That is easy to do, but the question is, how would you know when the > string starts and stops then? If you know your whole text is a string > and you are just stripping quotes there are much easier ways to do > that, the text I'm trying to parse is *kind* of file path, and things that know upfront is that: 1. the full text begins and end with a quote ("). 2. if there are quotes between then they are paired. eg. > otherwise, your grammar would become... interesting. That is > why C/C++/Python/Lua/Java/etc.../everything has you quote out a quote, > like with most \" puts in a literal quote instead of a delimiter. > Would be better to have more information on what you are actually > trying to do then. > actually I'm trying to parse third party tool output. Which looks like that: name="c:\exchange\test.zip " "files.txt"", info="" Regards, Anton ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: [qi]parsing of recursivly quoted textAnton Potapov
> the text I'm trying to parse is *kind* of file path, and things that know > upfront is that: > 1. the full text begins and end with a quote ("). > 2. if there are quotes between then they are paired. > eg. Ahh. So it isn't really recursive...they can only be nested one deep. Still, I don't see how you (even as a human being) would be able to tell the difference between a string nested in another string and a line with two disjoint strings on it. > actually I'm trying to parse third party tool output. Which looks like > that: > name="c:\exchange\test.zip " "files.txt"", info="" OK. This doesn't make sense at all. You have an odd number of quotes up there, so something isn't matched. Perhaps it should have started: name=""...? Assuming that's what you meant, you can probably work with a grammar that assumes a production like LINE ::= IDENTIFIER '=' '"' VALUE '"' EOL ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
|
|
Re: [qi]parsing of recursivly quoted text-----Original Message----- From: "Dennison, Ted" <Ted.Dennison@...> To: "Anton Potapov" <balanco@...>, "Spirit General Mailing List" <spirit-general@...> Date: Thu, 5 Nov 2009 08:43:32 -0600 Subject: RE: [Spirit-general][qi]parsing of recursivly quoted text > Anton Potapov > > the text I'm trying to parse is *kind* of file path, and things that > know > > upfront is that: > > 1. the full text begins and end with a quote ("). > > 2. if there are quotes between then they are paired. > > eg. > > Ahh. So it isn't really recursive...they can only be nested one deep. > > Still, I don't see how you (even as a human being) would be able to tell > the difference between a string nested in another string and a line with > two disjoint strings on it. In my case there is an assumption that text is *always* string nested in string. > > > actually I'm trying to parse third party tool output. Which looks like > > that: > > name="c:\exchange\test.zip " "files.txt"", info="" > > OK. This doesn't make sense at all. You have an odd number of quotes up > there, so something isn't matched. Perhaps it should have started: > name=""...? Sorry, looks like typo :). Intended string was : name="c:\exchange\test.zip > "files.txt"", info="" > > Assuming that's what you meant, you can probably work with a grammar > that assumes a production like > > LINE ::= IDENTIFIER '=' '"' VALUE '"' EOL not quite right. I would say something like : LINE ::= IDENTIFIER '=' '"' VALUE '"' ',' IDENTIFIER '=' '"' VALUE '"' EOL and VALUE can have quoted strings inside. regards, anton ------------------------------------------------------------------------------ Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day trial. Simplify your report design, integration and deployment - and focus on what you do best, core application coding. Discover what's new with Crystal Reports now. http://p.sf.net/sfu/bobj-july _______________________________________________ Spirit-general mailing list Spirit-general@... https://lists.sourceforge.net/lists/listinfo/spirit-general |
| Free embeddable forum powered by Nabble | Forum Help |