FAQ
hi folks,

I am playing around with PRD, and really like it so far. But I can quite
get my head around some details of the error reporting. consider the
following grammar:

code : fact(s?) eofile
{ $item[1] }
<error>
eofile : /^\Z/

fact : 'fact' <commit> identifier ';'
{ [$item[0], $item[3]] }
<error?><reject>
identifier : m{[A-Za-z_][A-Za-z0-9_]*}

and an input like this:

fact TFactA;
# case 1
# fact TFactB 234;
#
# case 2
# blablabla

the unmodified input parses nicely, and if I uncomment any of the two
syntax errors, it correctly rejects the input. excellent. but the error
reporting is slightly less than ideal: the error case 1 will set off the
<error> directive of the 'fact' rule (good), but *also* the <error>
directive of the 'code' rule, which is a bit odd. If I remove the error
directive of the parent rule, i'll miss errors of type 2, and if remove
the error directive of 'fact', then the error is reported in a very hard
to decipher way. Ideally i would like to have an error directive of most
rules in my syntax, but simply stop processing after I hit any of them.
Is there a way to achieve that?

I have read the FAQ and some other pages which talk about similar
problems, but please note that in this case the parser correctly rejects
the input, it just emits too many error messages

thanks robert

Search Discussions

  • Mark Hollomon at Nov 23, 2010 at 12:04 am
    This message probably won't thread well. I wasn't a member of the
    mailing list when Robert's original was sent. Sorry.

    Robert:

    Error messages in parsers are about as much art as science. Figuring
    out a good interface to allow PRD users to generate good error
    messages borders on black magic.
    the unmodified input parses nicely, and if I uncomment any of the two
    syntax errors, it correctly rejects the input. excellent. but the error
    reporting is slightly less than ideal: the error case 1 will set off the
    <error> directive of the 'fact' rule (good), but *also* the <error>
    directive of the 'code' rule, which is a bit odd.

    Believe it or not, the double error messages is considered a feature.
    PRD keeps a stack of error messages that it accumulates as it winds
    its way back up the call stack used for parsing. After all, it is
    possible that some rule "above" fact (meaning that it called "fact" or
    call a rule that called "fact" etc), is okay with the idea that "fact"
    failed and has something else to try.

    <error?> (and friends) are not "die". They do not force the parser to
    stop dead in its track. All they do is say to give up on the current
    rule - and record that fact - either through an autogenerated message
    or using a message the grammar writer supplies.

    If you truly want to stop dead, one option is to actually die:

    fact : <rulevar: $sawfact>
    'fact' {$sawfact = 1} <commit> identifier ';'
    <uncommit> { die "Something is rotten in state of Denmark at
    line $thisline\n" if $sawfact }

    Of course, the surrounding script better be ready for the exception...

    I hope this was helpful.

    Mark.

    If you are bound to

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprecdescent @
categoriesperl
postedNov 8, '10 at 7:02p
activeNov 23, '10 at 12:04a
posts2
users2
websitemetacpan.org...

2 users in discussion

Robert Lemmen: 1 post Mark Hollomon: 1 post

People

Translate

site design / logo © 2019 Grokbase