Browse files

Don't overwrite %item with repeated subrule matches in a production.

*** NON-BACKWARDS COMPATIBLE CHANGE! *** A repetition directive
such as 'id(s /,/)' correctly creates a temporary @item variable
to hold the 'id's that are matched.  That @item variable is them
used to set the real $item[] entry for that repetition.  The
same treatment is now given to %item.  Formerly, in a production like:

    id ',' id(s /,/)

matched against:

    xxx, yyy, zzz

The $item{id} entry which should be 'xxx' is overwritten by
'yyy' and then 'zzz' prior to the action being executed.  Now
'yyy' and 'zzz' set $item{id}, but in the private %item, which
goes out of scope once the repetition match completes.
  • Loading branch information...
1 parent d8875d0 commit 558f536be12e9c23b5558e409efbe8ea9c904b18 @jtbraun committed Feb 6, 2012
Showing with 20 additions and 20 deletions.
  1. +17 −0 Changes
  2. +0 −18 ToDo
  3. +3 −2 lib/Parse/RecDescent.pm
View
17 Changes
@@ -703,3 +703,20 @@ NEXT_VERSION NEXT_RELEASE
- Warn on empty productions followed by other productions. The
empty production always matches, so following productions will
never be reached.
+
+ - *** NON-BACKWARDS COMPATIBLE CHANGE! *** A repetition directive
+ such as 'id(s /,/)' correctly creates a temporary @item variable
+ to hold the 'id's that are matched. That @item variable is them
+ used to set the real $item[] entry for that repetition. The
+ same treatment is now given to %item. Formerly, in a production like:
+
+ id ',' id(s /,/)
+
+ matched against:
+
+ xxx, yyy, zzz
+
+ The $item{id} entry which should be 'xxx' is overwritten by
+ 'yyy' and then 'zzz' prior to the action being executed. Now
+ 'yyy' and 'zzz' set $item{id}, but in the private %item, which
+ goes out of scope once the repetition match completes.
View
18 ToDo
@@ -342,21 +342,3 @@ END_OF_GRAMMAR
This is caused by a bug in Text::Balanced:
https://rt.cpan.org/Ticket/Display.html?id=74714
-
------cut----------cut----------cut----------cut----------cut----------cut-----
-
-This grammar reports back:
- ['xxx', 'zzzz']
-rather than the expected:
- ['xxx', 'xxx']
-
--------------------------------------------------------
-my $parser = new Parse::RecDescent (q {
-startrule : id ',' id(s /,/) {
- $return = [$item[1], $item{id}]
-}
-
-id : /\w+/ }) || die $@;
-my $text = 'xxx,yyyy,zzzz';
-print Dumper $parser->startrule(\$text);
--------------------------------------------------------
View
5 lib/Parse/RecDescent.pm
@@ -1647,7 +1647,8 @@ sub code($$$$)
OPLOOP: while (1)
{
$repcount = 0;
- my @item;
+ my @item;
+ my %item;
';
$code .= '
@@ -1746,7 +1747,7 @@ sub code($$$$)
$code .= '
last;
- }
+ } # end of OPLOOP
';
$code .= '

0 comments on commit 558f536

Please sign in to comment.