Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

Re^2: multiple occurences when using Parse::RecDescent

by graff (Chancellor)
on Mar 30, 2005 at 09:45 UTC ( #443389=note: print w/replies, xml ) Need Help??

in reply to Re: multiple occurences when using Parse::RecDescent
in thread multiple occurences when using Parse::RecDescent

For some reason, I couldn't get your rule to handle repeated ocurrences of the target pattern. Here's a variation that worked for me (and it includes printing out the "text" that it finds, to prove the result):
startrule: statement(s) statement: print open text end print: /\s*print\s*/ open: "'" text: /([^']*)/ {print " $item[1] "} end: "'"
Generally, for a grammar that's supposed to handle one or more of a basic top-level unit, it's easier/clearer to assign a name to that unit and have just that, plus "(s)", as the startrule, then break it down into components in a later rule.

UPDATE: The OP said: i need it so that it will allow this several times down the textarea and spot an error in any of the occurences.

To make it work that way, the startrule should be:

startrule: statement(s) /$/
which says that after matching one or more patterns that satisfy "statement", the parser should find the end-of-string. Without this, any string that starts with a valid statement will be accepted, regardless of any unmatchable content that follows.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://443389]
[shmem]: python sucks
[LanX]: keep your sexlife private, please!
[LanX]: ;-p
shmem spent 3 hours chasing a bug related to variable scoping
[shmem]: is there an equivalent to my in python? or 'use strict' ?
[LanX]: I doubt
[LanX]: only nonlocal in Py3
[shmem]: so, python sucks
LanX NSFW!!!

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (13)
As of 2018-03-20 17:50 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (256 votes). Check out past polls.