BNFC / bnfc

BNF Converter
http://bnfc.digitalgrammars.com/
583 stars 162 forks source link

Layout: closing explicit block does not close open implicit blocks #344

Closed andreasabel closed 3 years ago

andreasabel commented 3 years ago

This parses in haskell but not in a suitable grammar using BNFC's layout mechanism:

f = 5 + g where {
g = 3 + h where
  h = 2 }

The problem seems to be that implicit blocks are dropped from the layout stack without emitting layoutClose tokens, see: https://github.com/BNFC/bnfc/blob/71ebcee11831fab640bb9f39d11c927106d21304/source/src/BNFC/Backend/Haskell/CFtoLayout.hs#L127-L128

I am using this grammar:

layout toplevel;
separator nonempty Decl ";" ;

Empty.      Decl ::= ;
FunClause.  Decl ::= Ident "=" Expr WhereOpt;

layout "where";
YesWhere.   WhereOpt ::= "where" "{" [Decl] "}";
NoWhere.    WhereOpt ::= ;

EId.        Expr1 ::= Ident;
EInt.       Expr1 ::= Integer;
EPlus.      Expr  ::= Expr "+" Expr1;
coercions   Expr 1;