Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Maybe I don't understand the problem, but if you really hate typing so much, why not generalize the solution instead?

Not that I like to generalize things, because I usually end up un-generalizing them a few months later (stupid shifting requirements!), but it seems easier than playing with symbol table manipulations just to save a few keystrokes to me... am I missing something?

I'm thinking of something roughly along these lines... completely untested and possibly wrong code is below. ;-)

# make a table of regular expression patterns my %table = ( qr/(\d+)/ => 'INT', qr/([A-Z]\w*)/ => 'ID', .... # more tokens here ); my ($parser) = shift; my $s = $parser->YYData->{INPUT}; my @matches; # any matches found by our re go in here foreach my $re ( keys %table ) { # for each regexp, check to see if it matches, and # put all the captured values in @matches if it does @matches = ( $$s =~ m/\G$re/gc ); # return the appropriate token, and captures... return( $table{$re}, @matches) if (@matches); } # end search for a token match # token not found... put error handling here ...


In reply to Re: when $$s =~ m/\G.../gc is too verbose by Anonymous Monk
in thread when $$s =~ m/\G.../gc is too verbose by stefp

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others romping around the Monastery: (6)
    As of 2020-11-29 21:47 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found