pacc logo
pacc v0.3: Error handling

Next: , Previous: , Up: Top   [Contents][Index]


19 Error handling

In the event that the parser returns ‘0’ to indicate that the parse has failed, then you can call char *pacc_error(struct pacc_parser *) which returns a string indicating the furthest point in the input which the parser reached, and what it expected to find there.

Consider the following one-rule grammar:

FortySomething <- "forty-" ("four" → { 44 } / "five" → { 45 })

With the input ‘fifty-three’, the parser can make no progress at all, and pacc_error() returns ‘1:1: expected FortySomething’.

With the input ‘forty-three’, the first 6 characters are successfully parsed, and pacc_error() returns ‘1:7: expected "four", or "five"’.

Note that pacc_error() is the default name for the error function. If you used the ‘--name=NAME’ / ‘-n NAME’ flag, the error function will be called NAME_error instead.

There are currently some limitations on error handling.

  • Only one error can ever be reported. There is no option for error recovery. For example, a parser for a language like C on encountering an error should ideally discard input till the next ‘;’ or ‘}’, and then resume parsing and reporting further errors it may find. This cannot be achieved with a pacc-created parser yet.
  • Certain pacc constructs are syntactic sugar, and in the process of desugaring them, new rules are created. Currently errors may reference these names, which are meaningless to the end user. For example, if the above grammar is altered to the following by adding a ‘*’ after the first string:
    FortySomething ← "forty-"* ("four" → { 44 } / "five" → { 45 }) 
    

    then the input ‘forty-three’ produces the error ‘1:7: expected FortySomething:*:0, "four", or "five"’


Next: , Previous: , Up: Top   [Contents][Index]

Last updated: 2016-08-03 21:39:50 UTC

News

Porting and packaging

One thing pacc needs is more users. And, perhaps, one way to get more users is to reduce the friction in getting started with pacc. An obvious lubricant is packaging. Read More...

Release relief

Looking at _pacc_coords(), I noticed that it seemed to have the same realloc() bug that I'd just fixed in _pacc_result(). However, the "list of arrays" trick really wasn't going to work here. Read More...

See more news articles

feed