bnfc icon indicating copy to clipboard operation
bnfc copied to clipboard

The `nonempty` macro should result in the Haskell backend using the `NonEmpty` type?

Open MatthewDaggitt opened this issue 4 years ago • 2 comments

You can write separator nonempty Stmt "," in the grammar but the generated Abs file still uses the type [Stmt] rather than NonEmpty Stmt. This means that you have to duplicate the empty-case check again wherever you use the generated data type.

e.g.

ELitSeq.    Expr ::= "[" [Expr] "]";

separator nonempty Expr "";

results in

data Expr = ELitSeq [Expr]

rather than

data Expr = ELitSeq (NonEmpty Expr)

How hard would this be to fix and where would one start?

MatthewDaggitt avatar Jun 28 '21 06:06 MatthewDaggitt

I think this would be a nice improvement. This isn't hard to fix, it is more that this will be a backwards-incompatible change. So one has to provide a legacy mode. Or, in this case we could produce code using type List1 which is then a type synonym for either [ ] or Data.List.Nonempty depending on which module one includes.

andreasabel avatar Jun 28 '21 09:06 andreasabel

#267, flexible syntax tree production, would also fix the present issue.

andreasabel avatar Jul 13 '21 08:07 andreasabel