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

Rule Parameters

Thread Next
From:
Rod Adams
Date:
March 1, 2005 21:06
Subject:
Rule Parameters
Message ID:
422549C9.3060802@rodadams.net

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 
parameters.

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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About