RE: Parse::RecDescent and catenating (no skip match)
[email protected] ("Brian Michalk") Tue, 23 Jul 2002 08:52:30 -0500
| Newsgroups | perl.recdescent |
|---|---|
| Message-ID | <[email protected]> |
Thanks Marco for pointing out this list to me. I am a big fan of P::RD. I use it for documenting anything that resembles a protocol. It's great for developing the protocol, and then later to use in testing against all of the clients and servers to make sure they are compliant. Marco pointed out to me that I should set the skip character to null. This is fine for a small grammar, but the one I'm working on has 1,743 lines in it. I'm trying to clean it up by removing all of the explicit commas that separate the tokens. My example below is simple. My units are frequencies, temperatures, distances (miles, kilometers) and such. My ultimate goal is to be able to catenate two tokens without requiring a separator. I would like to set the $skip=",". And define my subrules appropriately to not require a separator. Any help is appreciated. > -----Original Message----- > From: Marco Baringer [mailto:[email protected]] > Sent: Tuesday, July 23, 2002 6:12 AM > To: Brian K. Michalk > Subject: Re: Parse::RecDescent and catenating (no skip match) > > > > Parse::RecDescent has its own mailing list: > > [email protected] > > [email protected] (Brian K. Michalk) writes: > > Ferinstance, I would like to have a comma separated text ($skip=",") > > and have some fields match without the skip character. > > > > ############################################### > > my $grammar = q{ > > { $skip = ","; } > > protocol : tempwater # water temperature > > tempair # air temperature > > | <error: "$text"> > > > > tempwater : temperature > > tempair : temperature > > > > # how do I define the following temperature def to match 100F? > > temperature : digits''units > > temperature : digits[]units > > temperature : digits//units > > temperature : digits/[]/units > > > > digits : /[-]?[0-9]+/ > > units : 'f' | 'F' # fahrenheit > > 'c' | 'C' # celcius > > } > > ############################################### > > your best bet would be to set $skip to '' and explicitly state where > whitespace can go (which in your case is no where): > > ############################################### > my $grammar = q{ > # notice how we have to fully qualify skip > { $Parse::RecDecent::skip = ""; } > protocol: temperature # water temperature > ',' > temperature # air temperature > | <error: "$text"> > > temperature: digits units > > digits: /[-]?[0-9]+/ > > units: /[FfCc]/ # fahrenheit or celcius > } > ############################################### > > -- > -Marco > Ring the bells that still can ring. > Forget your perfect offering. > There is a crack in everything. > That's how the light gets in. > -Leonard Cohen >