orangeduck/mpc

errors are not being raised after parsing a rule

Opened this issue · 2 comments

when the parser successfully parses a rule then errors parsing another rule due to it not being able to match any rules it should raise an error but it doesnt

for example

passedrule
failedrule

passedrule gets passed then failedrule gets silently skipped and halts the parsing but suceeds, and the ast tree only shows the ast for passedrule

failedrule

failedrule gets raised and error is reported since no rules previously match

Can you give an example?

I know this is a 2+ year old issue but I think I ran into the same problem. What I realized is that my top-level rule didn't have any start/end terminators, so the parser would just silently exit on any unrecognized input instead of failing with an error.

Notice the example language definition ends this way:

mpca_lang(MPCA_LANG_DEFAULT,
  " expression : <product> (('+' | '-') <product>)*; "
  " product    : <value>   (('*' | '/')   <value>)*; "
  " value      : /[0-9]+/ | '(' <expression> ')';    "
  " maths      : /^/ <expression> /$/;               ", // note start /^/ and end /$/ terminators
  Expr, Prod, Value, Maths, NULL);

But my last rule looked like this, without the terminators:

  " maths      : <expression> ;               ",

Once I put those in, the parser would properly error out on any unrecognized or invalid input.

Hope this helps!