BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
586 stars 165 forks source link

Another `non-exhaustive case` in generated layout code #421

Closed MatthewDaggitt closed 2 years ago

MatthewDaggitt commented 2 years ago

If you have a layout stop keyword but no corresponding layout keyword, you get a crash with a pattern match failure the same error as reported in #144.

For example if we have

....
layout "let";
layout stop "in";
....

and we write

spec : Prop
spec = forall x in d . true

gives

gen/hs/Vehicle/External/Layout.hs:(170,35)-(171,55): Non-exhaustive patterns in case

The offending generated code is:

  closingToken :: Position -> Block -> Token
  closingToken pos = sToken pos . \case
    Implicit (LayoutDelimiters _ _ (Just sy)) _ _ -> sy

which appears to have no case for Nothing.

Forgive me for not providing a full minimal example. Cutting down the grammar would be a lot of work. Hopefully this should be enough to diagnose the problem. If not then I can put in the time.

andreasabel commented 2 years ago

I can't reproduce this with 2.9.4 without more information, unfortunately. [Are you on 2.9.4?]

In 2.9.2 and 2.9.3 I can reproduce something like this with this grammar

layout "let";
layout stop "in";
layout toplevel;

Prg. P ::= [S] ;
separator S ";" ;

In.  S ::= "forall" Integer "in" Integer ;
Let. S ::= "let" "{" [S] "}" "in" Integer ;

and this input:

forall 4 in 3 

Error on 2.9.2:

TestIssue: LayoutIssue.hs:(166,35)-(167,55): Non-exhaustive patterns in case

Error on 2.9.3:

TestIssue: LayoutIssue.hs:(170,35)-(171,55): Non-exhaustive patterns in case

I suspect this is a 2.9.3 issue. Closing. Please reopen with some example grammar and input if this should persist in 2.9.4.

MatthewDaggitt commented 2 years ago

Yes, we were on 2.9.3. I can confirm that 2.9.4 fixes it. Apologies I should have checked the versions first.