Re: Hello, How to parse lists?
Seth <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
On 30-10-16 00:29, Jens Kallup wrote:
> parameter = alpha.input("parameter") > def_param
> def_param = alpha.input(alpha) |
> (alpha.input(alpha) > ',' > def_param)
> alpha = [a-zA-Z_][a-zA-Z0-9_]
Finally something we can work with. (remember I've asked for SSCCE or
goals for weeks).
Here's the simplest translation of the above:
ident = qi::char_("a-zA-Z_") >> qi::char_("a-zA-Z0-9_");
parameter = qi::lexeme["parameter"] >> (ident % ',');
First off, I think `alpha` should be `[a-zA-Z_][a-zA-Z0-9_]...` since
otherwise fff wouldn't match (too many characters)
ident = qi::char_("a-zA-Z_") >> *qi::char_("a-zA-Z0-9_");
Now it parses the test cases from your earlier mail
<http://coliru.stacked-crooked.com/a/e95fd41d4d4fe4a5>:
===== input 'parameter fff'
Ok: 1
Ident: fff
===== input 'parameter fff , ccc'
Ok: 2
Ident: fff
Ident: ccc
===== input 'parameter fff, ccc ddd ddd dd dd'
Ok: 2
Ident: fff
Ident: ccc
Remaining unparsed: 'ddd ddd dd dd'...
Now you wish for the last one to "fail"? I presume that might be because
end of input has not been reached. You can either check that the end
iterator is reached, or add `>> qi::eoi` to ensure that EOI
(end-of-input) was reached:
parameter = qi::lexeme["parameter"] >> (ident % ',') >> qi::eoi;
Then the output becomes
<http://coliru.stacked-crooked.com/a/95c7f4a181ff0713>:
===== input 'parameter fff'
Ok: 1
Ident: fff
===== input 'parameter fff , ccc'
Ok: 2
Ident: fff
Ident: ccc
===== input 'parameter fff, ccc ddd ddd dd dd'
Fail
Remaining unparsed: 'parameter fff, ccc ddd ddd dd dd'...
------------------------------------------------------------------------------
The Command Line: Reinvented for Modern Developers
Did the resurgence of CLI tooling catch you by surprise?
Reconnect with the command line and become more productive.
Learn the new .NET and ASP.NET CLI. Get your free copy!
http://sdm.link/telerik
_______________________________________________
Spirit-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/spirit-general