orangeduck / mpc

A Parser Combinator library for C
Other
2.68k stars 295 forks source link

errors are not being raised after parsing a rule #102

Open mgood7123 opened 5 years ago

mgood7123 commented 5 years ago

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

orangeduck commented 5 years ago

Can you give an example?

ghaberek commented 3 years ago

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!