Separating function declarations in an LBNF grammar

47 Views Asked by At

I have the following simple LBNF grammar (it's a fragment, don't try to compile):

ProgDef .  Program ::= [FunDec] ;

TypeBit    . Type  ::= "Bit" ;

position token Var ((lower | '_') (letter | digit | '_' | '\'')*) ;

FunArg . Arg ::= Var ;
separator Arg " " ;

FunDef . Function ::= Var [Arg] "=" Term ;

FunDecl . FunDec ::= Var "::" Type Function ;
separator FunDec "#" ;

When I parse the following source code:

main :: Bit   
main = fun1 fun2
#
main :: Bit
main = fun1 fun2

The syntax and parsing work fine. However, I want to get rid of the '#' character separating the function declarations and replace it with an empty line. How can I achieve this?

1

There are 1 best solutions below

0
Radu M. On BEST ANSWER

Here is what worked for me:

layout toplevel ;

ProgDef .  Program ::= [FunDec] ;

FunArg . Arg ::= Var ;
separator Arg " " ;

FunDef . Function ::= Var [Arg] "=" Term ;

FunDecl . FunDec ::= Var "::" Type ";" Function ";" ;
separator FunDec "" ;