Package: libparse-recdescent-perl
Version: 1.94-1
Severity: minor

Hi!

The tutorial mentions multiple times returning values from actions. One
things it fails to mention is that calling return in an action is
completly different from setting $return or just specifying the value as
the last statement. See the attached example, and see the attached diff
file for how removing the "return" changes the output. This is all the
more difficult to debug, that the message:

>>Matched subrule: [gallery]<< (return value: [1]

is present even in the failing case, even though the parser retracts to
the beginning, as the third column suggests. So it's somewhat
misleading.

This has taken me several long hours to find out (in a more complicated
grammar), and I really would like to make this one thing more visible in
the documentation, so that noone will have to waste his time again.

regards,

Marcin

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable'), (1, 'experimental')
Architecture: i386 (i686)
Kernel: Linux 2.4.27-2-k7
Locale: LANG=pl_PL, LC_CTYPE=pl_PL (charmap=ISO-8859-2)

Versions of packages libparse-recdescent-perl depends on:
ii  perl                          5.8.4-6    Larry Wall's Practical Extraction 

-- no debconf information

Attachment: a_test
Description: Perl program

Attachment: a_test_no_return
Description: Perl program

--- a_test      2005-03-03 15:35:42.000000000 +0100
+++ a_test_no_return    2005-03-03 15:36:09.000000000 +0100
@@ -12,7 +12,7 @@
 
 gallery: 'gallery' label '{' desc(s) '}' ';'
        {
-               return 1;
+               1;
        }
 
 desc: 'desc' '"' /[^"]*/ '"' ';' { $item[3] }
Script started on czw 03 mar 2005 15:38:49 CET
]0;[EMAIL PROTECTED]: /home/porridge/[EMAIL PROTECTED]:~/tmp$ ./a_de  test
    Parse::RecDescent: Treating "config:" as a rule declaration
    Parse::RecDescent: Treating "gallery" as a subrule match
    Parse::RecDescent: Treating "EE" as a literal terminal
    Parse::RecDescent: Treating "gallery:" as a rule declaration
    Parse::RecDescent: Treating "gallery" as a literal terminal
    Parse::RecDescent: Treating "label" as a subrule match
    Parse::RecDescent: Treating "{" as a literal terminal
    Parse::RecDescent: Treating "desc(s)" as a one-or-more subrule match
    Parse::RecDescent: Treating "}" as a literal terminal
    Parse::RecDescent: Treating ";" as a literal terminal
    Parse::RecDescent: Treating "{ return 1; }" as an action
    Parse::RecDescent: Treating "desc:" as a rule declaration
    Parse::RecDescent: Treating "desc" as a literal terminal
    Parse::RecDescent: Treating """ as a literal terminal
    Parse::RecDescent: Treating "/[^"]*/" as a /../ pattern terminal
    Parse::RecDescent: Treating """ as a literal terminal
    Parse::RecDescent: Treating ";" as a literal terminal
    Parse::RecDescent: Treating "{ $item[3] }" as an action
    Parse::RecDescent: Treating "label:" as a rule declaration
    Parse::RecDescent: Treating "/\w+/" as a /../ pattern terminal
printing code (22472) to RD_TRACE
 1|  config  |Trying rule: [config]                 |
 1|  config  |                                      |"gallery exim { desc "foo";
  |          |                                      |}; EE"
 1|  config  |Trying production: [gallery 'EE']     |
 1|  config  |Trying subrule: [gallery]             |
 2| gallery  |Trying rule: [gallery]                |
 2| gallery  |Trying production: ['gallery' label   |
  |          |'{' desc '}' ';']                     |
 2| gallery  |Trying terminal: ['gallery']          |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[gallery])                            |
 2| gallery  |                                      |" exim { desc "foo"; }; EE"
 2| gallery  |Trying subrule: [label]               |
 3|  label   |Trying rule: [label]                  |
 3|  label   |Trying production: [/\w+/]            |
 3|  label   |Trying terminal: [/\w+/]              |
 3|  label   |>>Matched terminal<< (return value:   |
  |          |[exim])                               |
 3|  label   |                                      |" { desc "foo"; }; EE"
 3|  label   |>>Matched production: [/\w+/]<<       |
 3|  label   |>>Matched rule<< (return value:       |
  |          |[exim])                               |
 3|  label   |(consumed: [ exim])                   |
 2| gallery  |>>Matched subrule: [label]<< (return  |
  |          |value: [exim]                         |
 2| gallery  |Trying terminal: ['{']                |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[{])                                  |
 2| gallery  |                                      |" desc "foo"; }; EE"
 2| gallery  |Trying repeated subrule: [desc]       |
 3|   desc   |Trying rule: [desc]                   |
 3|   desc   |Trying production: ['desc' '"' /[^"]*/|
  |          |'"' ';']                              |
 3|   desc   |Trying terminal: ['desc']             |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |[desc])                               |
 3|   desc   |                                      |" "foo"; }; EE"
 3|   desc   |Trying terminal: ['"']                |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |["])                                  |
 3|   desc   |                                      |"foo"; }; EE"
 3|   desc   |Trying terminal: [/[^"]*/]            |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |[foo])                                |
 3|   desc   |                                      |""; }; EE"
 3|   desc   |Trying terminal: ['"']                |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |["])                                  |
 3|   desc   |                                      |"; }; EE"
 3|   desc   |Trying terminal: [';']                |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |[;])                                  |
 3|   desc   |                                      |" }; EE"
 3|   desc   |Trying action                         |
 3|   desc   |>>Matched action<< (return value:     |
  |          |[foo])                                |
 3|   desc   |>>Matched production: ['desc' '"'     |
  |          |/[^"]*/ '"' ';']<<                    |
 3|   desc   |>>Matched rule<< (return value: [foo])|
 3|   desc   |(consumed: [ desc "foo";])            |
 3|   desc   |Trying rule: [desc]                   |
 3|   desc   |Trying production: ['desc' '"' /[^"]*/|
  |          |'"' ';']                              |
 3|   desc   |Trying terminal: ['desc']             |
 3|   desc   |<<Didn't match terminal>>             |
 3|   desc   |                                      |"}; EE"
 3|   desc   |<<Didn't match rule>>                 |
 2| gallery  |>>Matched repeated subrule: [desc]<<  |
  |          |(1 times)                             |
 2| gallery  |                                      |" }; EE"
 2| gallery  |Trying terminal: ['}']                |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[}])                                  |
 2| gallery  |                                      |"; EE"
 2| gallery  |Trying terminal: [';']                |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[;])                                  |
 2| gallery  |                                      |" EE"
 2| gallery  |Trying action                         |
 1|  config  |>>Matched subrule: [gallery]<< (return|
  |          |value: [1]                            |
 1|  config  |                                      |"gallery exim { desc "foo";
  |          |                                      |}; EE"
 1|  config  |Trying terminal: ['EE']               |
 1|  config  |<<Didn't match terminal>>             |
 1|  config  |<<Didn't match rule>>                 |
parse returned undef
]0;[EMAIL PROTECTED]: /home/porridge/[EMAIL PROTECTED]:~/tmp$ 
Script done on czw 03 mar 2005 15:38:55 CET
Script started on czw 03 mar 2005 15:39:28 CET
]0;[EMAIL PROTECTED]: /home/porridge/[EMAIL PROTECTED]:~/tmp$ 
./a_test_no_return
    Parse::RecDescent: Treating "config:" as a rule declaration
    Parse::RecDescent: Treating "gallery" as a subrule match
    Parse::RecDescent: Treating "EE" as a literal terminal
    Parse::RecDescent: Treating "gallery:" as a rule declaration
    Parse::RecDescent: Treating "gallery" as a literal terminal
    Parse::RecDescent: Treating "label" as a subrule match
    Parse::RecDescent: Treating "{" as a literal terminal
    Parse::RecDescent: Treating "desc(s)" as a one-or-more subrule match
    Parse::RecDescent: Treating "}" as a literal terminal
    Parse::RecDescent: Treating ";" as a literal terminal
    Parse::RecDescent: Treating "{ 1; }" as an action
    Parse::RecDescent: Treating "desc:" as a rule declaration
    Parse::RecDescent: Treating "desc" as a literal terminal
    Parse::RecDescent: Treating """ as a literal terminal
    Parse::RecDescent: Treating "/[^"]*/" as a /../ pattern terminal
    Parse::RecDescent: Treating """ as a literal terminal
    Parse::RecDescent: Treating ";" as a literal terminal
    Parse::RecDescent: Treating "{ $item[3] }" as an action
    Parse::RecDescent: Treating "label:" as a rule declaration
    Parse::RecDescent: Treating "/\w+/" as a /../ pattern terminal
printing code (22465) to RD_TRACE
 1|  config  |Trying rule: [config]                 |
 1|  config  |                                      |"gallery exim { desc "foo";
  |          |                                      |}; EE"
 1|  config  |Trying production: [gallery 'EE']     |
 1|  config  |Trying subrule: [gallery]             |
 2| gallery  |Trying rule: [gallery]                |
 2| gallery  |Trying production: ['gallery' label   |
  |          |'{' desc '}' ';']                     |
 2| gallery  |Trying terminal: ['gallery']          |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[gallery])                            |
 2| gallery  |                                      |" exim { desc "foo"; }; EE"
 2| gallery  |Trying subrule: [label]               |
 3|  label   |Trying rule: [label]                  |
 3|  label   |Trying production: [/\w+/]            |
 3|  label   |Trying terminal: [/\w+/]              |
 3|  label   |>>Matched terminal<< (return value:   |
  |          |[exim])                               |
 3|  label   |                                      |" { desc "foo"; }; EE"
 3|  label   |>>Matched production: [/\w+/]<<       |
 3|  label   |>>Matched rule<< (return value:       |
  |          |[exim])                               |
 3|  label   |(consumed: [ exim])                   |
 2| gallery  |>>Matched subrule: [label]<< (return  |
  |          |value: [exim]                         |
 2| gallery  |Trying terminal: ['{']                |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[{])                                  |
 2| gallery  |                                      |" desc "foo"; }; EE"
 2| gallery  |Trying repeated subrule: [desc]       |
 3|   desc   |Trying rule: [desc]                   |
 3|   desc   |Trying production: ['desc' '"' /[^"]*/|
  |          |'"' ';']                              |
 3|   desc   |Trying terminal: ['desc']             |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |[desc])                               |
 3|   desc   |                                      |" "foo"; }; EE"
 3|   desc   |Trying terminal: ['"']                |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |["])                                  |
 3|   desc   |                                      |"foo"; }; EE"
 3|   desc   |Trying terminal: [/[^"]*/]            |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |[foo])                                |
 3|   desc   |                                      |""; }; EE"
 3|   desc   |Trying terminal: ['"']                |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |["])                                  |
 3|   desc   |                                      |"; }; EE"
 3|   desc   |Trying terminal: [';']                |
 3|   desc   |>>Matched terminal<< (return value:   |
  |          |[;])                                  |
 3|   desc   |                                      |" }; EE"
 3|   desc   |Trying action                         |
 3|   desc   |>>Matched action<< (return value:     |
  |          |[foo])                                |
 3|   desc   |>>Matched production: ['desc' '"'     |
  |          |/[^"]*/ '"' ';']<<                    |
 3|   desc   |>>Matched rule<< (return value: [foo])|
 3|   desc   |(consumed: [ desc "foo";])            |
 3|   desc   |Trying rule: [desc]                   |
 3|   desc   |Trying production: ['desc' '"' /[^"]*/|
  |          |'"' ';']                              |
 3|   desc   |Trying terminal: ['desc']             |
 3|   desc   |<<Didn't match terminal>>             |
 3|   desc   |                                      |"}; EE"
 3|   desc   |<<Didn't match rule>>                 |
 2| gallery  |>>Matched repeated subrule: [desc]<<  |
  |          |(1 times)                             |
 2| gallery  |                                      |" }; EE"
 2| gallery  |Trying terminal: ['}']                |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[}])                                  |
 2| gallery  |                                      |"; EE"
 2| gallery  |Trying terminal: [';']                |
 2| gallery  |>>Matched terminal<< (return value:   |
  |          |[;])                                  |
 2| gallery  |                                      |" EE"
 2| gallery  |Trying action                         |
 2| gallery  |>>Matched action<< (return value: [1])|
 2| gallery  |>>Matched production: ['gallery' label|
  |          |'{' desc '}' ';']<<                   |
 2| gallery  |>>Matched rule<< (return value: [1])  |
 2| gallery  |(consumed: [gallery exim { desc "foo";|
  |          |};])                                  |
 1|  config  |>>Matched subrule: [gallery]<< (return|
  |          |value: [1]                            |
 1|  config  |Trying terminal: ['EE']               |
 1|  config  |>>Matched terminal<< (return value:   |
  |          |[EE])                                 |
 1|  config  |>>Matched production: [gallery 'EE']<<|
 1|  config  |>>Matched rule<< (return value: [EE]) |
 1|  config  |(consumed: [])                        |
?:$VAR1 = 'EE';
]0;[EMAIL PROTECTED]: /home/porridge/[EMAIL PROTECTED]:~/tmp$ 
Script done on czw 03 mar 2005 15:39:34 CET
--- parser1     2005-03-03 15:38:55.000000000 +0100
+++ parser2     2005-03-03 15:39:34.000000000 +0100
@@ -10,7 +10,7 @@
     Parse::RecDescent: Treating "desc(s)" as a one-or-more subrule match
     Parse::RecDescent: Treating "}" as a literal terminal
     Parse::RecDescent: Treating ";" as a literal terminal
-    Parse::RecDescent: Treating "{ return 1; }" as an action
+    Parse::RecDescent: Treating "{ 1; }" as an action
     Parse::RecDescent: Treating "desc:" as a rule declaration
     Parse::RecDescent: Treating "desc" as a literal terminal
     Parse::RecDescent: Treating """ as a literal terminal
@@ -20,7 +20,7 @@
     Parse::RecDescent: Treating "{ $item[3] }" as an action
     Parse::RecDescent: Treating "label:" as a rule declaration
     Parse::RecDescent: Treating "/\w+/" as a /../ pattern terminal
-printing code (22472) to RD_TRACE
+printing code (22465) to RD_TRACE
  1|  config  |Trying rule: [config]                 |
  1|  config  |                                      |"gallery exim { desc 
"foo";
   |          |                                      |}; EE"
@@ -100,13 +100,20 @@
   |          |[;])                                  |
  2| gallery  |                                      |" EE"
  2| gallery  |Trying action                         |
+ 2| gallery  |>>Matched action<< (return value: [1])|
+ 2| gallery  |>>Matched production: ['gallery' label|
+  |          |'{' desc '}' ';']<<                   |
+ 2| gallery  |>>Matched rule<< (return value: [1])  |
+ 2| gallery  |(consumed: [gallery exim { desc "foo";|
+  |          |};])                                  |
  1|  config  |>>Matched subrule: [gallery]<< (return|
   |          |value: [1]                            |
- 1|  config  |                                      |"gallery exim { desc 
"foo";
-  |          |                                      |}; EE"
  1|  config  |Trying terminal: ['EE']               |
- 1|  config  |<<Didn't match terminal>>             |
- 1|  config  |<<Didn't match rule>>                 |
-parse returned undef
+ 1|  config  |>>Matched terminal<< (return value:   |
+  |          |[EE])                                 |
+ 1|  config  |>>Matched production: [gallery 'EE']<<|
+ 1|  config  |>>Matched rule<< (return value: [EE]) |
+ 1|  config  |(consumed: [])                        |
+?:$VAR1 = 'EE';
 ]0;[EMAIL PROTECTED]: /home/porridge/[EMAIL PROTECTED]:~/tmp$ 

Reply via email to