Boost::Spirit - Just enough to match a term?
I'm past the initial learning curve with Spirit, but would like to see how the pros handle this problem. I have the following simple command structure: show queues show users show processes start process foo queue user bar to process foo ...etc I would like to parse these commands with Spirit. Easy enough. Since this is being entered from a keyboard, it would be nice to short-circuit the parser so you only have to enter enough of the command for the parser to reliably figure out what you want. e.g. "sh qu" would parse as "show queues", and "st pr foo" would parse as "start process foo". I can easily model the whole "show queues" command word with: str_p("show") >> str_p("queues") But how do I match "just enough" instead of "whole word" without doing it manually? TIA, Eric
On 7/12/06, Eric Hill
I'm past the initial learning curve with Spirit, but would like to see how the pros handle this problem.
I have the following simple command structure:
show queues show users show processes start process foo queue user bar to process foo ...etc
I would like to parse these commands with Spirit. Easy enough. Since this is being entered from a keyboard, it would be nice to short-circuit the parser so you only have to enter enough of the command for the parser to reliably figure out what you want.
e.g. "sh qu" would parse as "show queues", and "st pr foo" would parse as "start process foo".
I can easily model the whole "show queues" command word with:
str_p("show") >> str_p("queues")
But how do I match "just enough" instead of "whole word" without doing it manually?
TIA, Eric
There's nothing built in to do that (AFAIK). However, it is relatively trivial to implement using a functor parser. I've done it myself - however, the code's at work, and I'm not :-) I'll post some code tomorrow after work (haven't got access to this e-mail account there!). Anyway, the strategy I followed was to initialise the functor parser with a set of tokens and it would generate the set of unambiguous prefixes. Then the functor parser would match tokens that matched the required words to sufficient length. Stuart Dootson Stuart Dootson
On 7/12/06, Stuart Dootson
On 7/12/06, Eric Hill
wrote:
<snip>
But how do I match "just enough" instead of "whole word" without doing it manually?
TIA, Eric
There's nothing built in to do that (AFAIK). However, it is relatively trivial to implement using a functor parser. I've done it myself - however, the code's at work, and I'm not :-) I'll post some code tomorrow after work (haven't got access to this e-mail account there!).
Stuart Dootson
As promised... disambiguate.h is the parser implementation, dis.cpp is a sample parser using it. There are two main sections in disambiguate.h. The first contains the implementation of the Disambiguator class. This determines the minimum unambiguous prefix for each token you add to it. The second section contains the min_unambiguous_parser_f class, which is the parser. This uses an associated Disambiguator together with the user supplied complete keyword to match any unambiguous prefix of the keyword. There are several min_unambig_p overloads that you use in a parser to create a min_unambiguous_parser_f. The one thing I'm not sure about is the ~epsilon_p I've got that ensures that the character following the keyword isn't in [a-zA-Z0-9_] - it should probably be something else? But I'm not sure what. Anyway - hope that's of use/interest... Stuart Dootson
Hello all, I have been trying to build boost 1.33.1 for 64 bit AIX 5.3 on power 5 with eIther gcc or vaccp for a month now. I have tried many, many, ways and have no success. Has anyone ever succeeded? If someone has can you please provide the method of configuration. Kamil Kamil Marcinkowski Westgrid System Administrator kamil@ualberta.ca University of Alberta site Tel.780 492-0354 Research Computing Support Fax.780 492-1729 Academic ICT Edmonton, Alberta, CANADA University of Alberta "This communication is intended for the use of the recipient to which it is addressed, and may contain confidential, personal, and/or privileged information. Please contact us immediately if you are not the intended recipient of this communication. If you are not the intended recipient of this communication, do not copy, distribute, or take action on it. Any communication received in error, or subsequent reply, should be deleted or destroyed."
participants (3)
-
Eric Hill
-
kamil Marcinkowski
-
Stuart Dootson