develooper Front page | perl.perl6.language | Postings from March 2005

Rule Parameters

Thread Next
Rod Adams
March 1, 2005 21:06
Rule Parameters
Message ID:

Since the line between rules and subs is already blurring significantly, 
I want to blur it a little more. I want to write rules which can take 

Consider that I am parsing HTML (a very frequent occurrence), and wish 
to make a Rule that matches a balanced tag from open to close.  I  want 
to use the same code many different times, but for different tags. So I 
really want to say something like:

    rule baltag (Rule|Str $<tag>) {
      \< $<tag> \s* $<options> := (.*?) \>
      $<body> := (.*?)
      \</ $<tag> \>

I could then do:

    $buffer ~~ / <baltag title> /;

later on to match any <title> tag in my buffer.

I'm open to alternative syntaxs, this one was just there to illustrate 
my point.

-- Rod Adams.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About