BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
582 stars 161 forks source link

Make `closingToken` function pattern matching exhaustive #399

Closed VBeatrice closed 2 years ago

VBeatrice commented 2 years ago

The closingToken function cases in the layout solver were not exhaustive

andreasabel commented 2 years ago

Mmh, I am not sure. This gives a better error message, but still closingToken will make the layouter crash when it shouldn't, won't it? What about the round-trip example (parse/print/parse) for the Alfa.cf grammar?

VBeatrice commented 2 years ago

closingToken crashes if one tries to resolve the layouts of a file where the layouts have already been resolved a first time. (when the grammar uses the top level layout pragma)

In the round-trip test the layouts are resolved once, before the first parsing.

andreasabel commented 2 years ago

Now I finally found a small reproducer:

terminator Exp ";"                         ;
layout toplevel                            ;

Var. Exp ::= Ident;
Let. Exp ::= "let" "{" [Exp] "}" "in" Exp  ;

layout "let"                               ;
layout stop "in"                           ;

Input:

let {}
in x

Error is:

TestTest: Layout error at line 2, column 4: trying to close a top level block.
Remaining tokens: x

This seems to be a problem with the implementation of layout stop.