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.startrule: statement(s) statement: print open text end print: /\s*print\s*/ open: "'" text: /([^']*)/ {print " $item[1] "} end: "'"
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:
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.startrule: statement(s) /$/
In reply to Re^2: multiple occurences when using Parse::RecDescent
by graff
in thread multiple occurences when using Parse::RecDescent
by hak0983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |