From: <jpa...@gm...> - 2006-03-27 10:56:04
|
AI wrote: > Hello all, > > I am novice in spirit and stuck with something trivial. 2 questions: > > The syntax I want to parse is really simple: > <something> : <something else> > > where <something else> can be one of: > 0x<one or more hexadecimal digits> > 0b<one or more binary digits> > <one or more decimal digits> > "<one or more printable characters except">" > > for example: > file_name : "c:\Program Files" > one: 1 > ten :0xa > > Following code was written to parse this syntax: [ snip code snippet ] Please come up with minimal but complete code examples and attach them to your messages so we can directly try! It makes helping you so much easier. Thanks. > Note the commented out lines supposedly parsing hexadecimal, binary and decimal > numbers. The parser can not match > file_name : "c:\asd" > if those lines are uncommented. Are you missing some rules to parse the line-endings? If you're not using a skip parser, why use lexeme_d? > QUESTION #1: since those subexpressions are connected with "|", how come that > REMOVING one of them will produce MORE matches? What am I missing? For that > matter, what would be CORRECT parser definition for this syntax? It seems that any of the alternatives will only match once. Once it matches that's the end of the story. You may need something like, >> *( ( option1 | option2 | ... ) >> eol_p ) >> ... in order to match multiple lines. > QUESTION #2: in the first part of expression (dealing with <something> part), > note the *blank_p parsers. Without them the parser will not match expressions > containing spaces around ':'. Which in turn means that lexeme_d will alter > behaviour of not only enclosed parser, but all parsers in the expression. Is > this correct? If you want to allow whitespace you must explicitly make it so using blank_p (or similar) as needed in the grammar. If you follow this approach, lexeme_d does nothing for you. For minimal effort whitespace skipping you could use a skipper, parse(begin, end, parser, skipper) in this case you will have to surround pieces where whitespace is forbidden with lexeme_d, as you did in your sample. Regards, João |