Skip Menu |

This queue is for tickets about the Marpa-R2 CPAN distribution.

Report information
The Basics
Id: 82166
Status: resolved
Priority: 0/
Queue: Marpa-R2

People
Owner: jkegl [...] cpan.org
Requestors: feratilbeau [...] hotmail.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 2.033_000
Fixed in: (no value)



Subject: Problem in g->rule_rank_set(5, -2)
Hello, I just hitted this message. The grammar is quite big (hundreds of rules and tokens), so I wonder if it is possible to have a more meaningful message? That could help to disect if the error is in the grammar or in Marpa::R2. I can say that the grammar itself have ranks all over the place, with no exception, every first rhs of every rule have a rank => 0, then the rank decreases by 1 at every '|'. The grammar precomputes fine without rank. Thanks, Cheers, Jean-Damien.
From: feratilbeau [...] hotmail.com
Just in case it can help, the full backtrace is: % perl -I blib/lib t/xml-1.0-5th-edition.t 1..3 # Running under perl version 5.014002 for linux # Current time local: Sat Dec 22 00:26:02 2012 # Current time GMT: Fri Dec 21 23:26:02 2012 # Using Test.pm version 1.25_02 ok 1 Uncaught exception from user code: Problem in g->rule_rank_set(5, -2): No error at /usr/local/lib/perl/5.14.2/Marpa/R2/Grammar.pm line 1209. at /usr/local/lib/perl/5.14.2/Marpa/R2/Grammar.pm line 1208 Marpa::R2::Internal::Grammar::add_user_rule('Marpa::R2::Grammar=ARRAY(0x89ce740)', 'HASH(0x8358b6c)') called at /usr/local/lib/perl/5.14.2/Marpa/R2/Grammar.pm line 1026 Marpa::R2::Internal::Grammar::add_user_rules('Marpa::R2::Grammar=ARRAY(0x89ce740)', 'ARRAY(0x8bde1ac)') called at /usr/local/lib/perl/5.14.2/Marpa/R2/Grammar.pm line 350 Marpa::R2::Grammar::set('Marpa::R2::Grammar=ARRAY(0x89ce740)', 'HASH(0x8be9138)') called at /usr/local/lib/perl/5.14.2/Marpa/R2/Grammar.pm line 163 Marpa::R2::Grammar::new('Marpa::R2::Grammar', 'HASH(0x8be9138)') called at blib/lib/Marpa/EBNF.pm line 2567 Marpa::EBNF::grammar('Marpa::EBNF=HASH(0x855b32c)', '--p\x{a}Source: http://www.w3.org/TR/REC-xml/\x{a} http://www....') called at t/xml-1.0-5th-edition.t line 107 Le Ven 21 Déc 2012 18:33:22, jddfr74 a écrit : Show quoted text
> Hello, > > I just hitted this message. The grammar is quite big (hundreds of rules > and tokens), so I wonder if it is possible to have a more meaningful > message? That could help to disect if the error is in the grammar or in > Marpa::R2. > > I can say that the grammar itself have ranks all over the place, with no > exception, every first rhs of every rule have a rank => 0, then the rank > decreases by 1 at every '|'. > > The grammar precomputes fine without rank. > > Thanks, Cheers, Jean-Damien.
It's a Libmarpa problem. With 15,000 lines of C code and a huge grammar, this is the stuff of nightmares, so I'm happy to say it seems to be a pretty obvious piece of stupidity on my part. The *_rank_set() calls return the new rank, or a negative error code. However, ranks can be negative (as is your case), in which case Marpa reports a non-existent error. I have to change the return value, but do not want to take Libmarpa to a new major number just for this. One thought is to redocument that *_rank_set() returns a non-negative number on success, -1 or -2 on failure. I then have them return 0 for all negative ranks. By the way, a work-around is probably not to use negative ranks. It's also another way to solve the problem -- since they never worked anyway, forbid negative ranks. That might be simplest. @Jean-Damien: Thoughts?
From: feratilbeau [...] hotmail.com
Show quoted text
> By the way, a work-around is probably not to use negative ranks
No problem, so will I -; Thanks for your help, Cheers, JD. Show quoted text
> I have to change the return value, but do not want to take Libmarpa to > a new major number just > for this. One thought is to redocument that *_rank_set() returns a > non-negative number on > success, -1 or -2 on failure. I then have them return 0 for all > negative ranks. > > By the way, a work-around is probably not to use negative ranks. It's > also another way to solve > the problem -- since they never worked anyway, forbid negative ranks. > That might be simplest. > > @Jean-Damien: Thoughts?
I made a fix and uploaded it to CPAN as Marpa-R2-2.033_002.tar.gz. There's a new test for negative ranks in the test suite: rank.t. At the Marpa::R2 level things are unchanged, except that negative ranks now work. At the Marpa::R2::Thin level, I've changed the calls to check for whether an error actually occurred before throwing one. A -2 return is ambiguous (that is, it can be either success for a rank of -2 or failure). This is now documented. At the Libmarpa level, I cleaned up the code, and made sure that the calls which return and/or set ranks always clear the error code back to MARPA_ERR_NONE on success. This allows the upper levels a safe way to clearly determine whether or not a failure occurred. I've revised and clarified the Libmarpa documentation. Interfaces whose return codes do not indicate errors unambiguously, and which need to be double-checked, are known. They occur in cases like this, where "natural" return values cover most of all the possible return values, leaving no obvious choice of a return value to use for exceptions and/or errors. But they're unusual -- I don't really like them and I imagine my sentiment is shared. Most libraries figure out some way to avoid ambiguous error returns. But this interface preserves backward compatibility --any code which currently works will continue to work.
Fixed in CPAN 2.034000. Thanks!
From: feratilbeau [...] hotmail.com
Thank you very much - tested and it works. Cheers, JD. Le Mer 26 Déc 2012 19:25:39, JKEGL a écrit : Show quoted text
> Fixed in CPAN 2.034000. Thanks!
From: feratilbeau [...] hotmail.com
Oups, the previous answer has reopened the ticket - sorry for that. Le Sam 29 Déc 2012 03:19:09, jddfr74 a écrit : Show quoted text
> Thank you very much - tested and it works. > Cheers, JD. > > Le Mer 26 Déc 2012 19:25:39, JKEGL a écrit :
> > Fixed in CPAN 2.034000. Thanks!
>