BNFC / bnfc

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

Layout resolver #29

Closed mantkiew closed 11 years ago

mantkiew commented 11 years ago

What is the status of the layout resolver? It seems it has not been updated since three years ago. It seems to be only limited to having special keywords that open up the nested blocks. In our language, we don't have explicit keyword that mark the beginning of the block. Nesting is simply allowed after each declaration. For example,

abstract Person
   name : string
   spouse -> Person ?
       year : integer
   child -> Person *

Is resolving such layout possible?

gdetrez commented 11 years ago

I don't know the layout resolver very well but it seems really basic so I would think this is not possible to do with BNFC directly. But this is what the manual says:

In Haskell, the layout resolver appears, automatically, in its most natural place, which is between the lexer and the parser.

So one way to implement a more sophisticated layout resolver using bnfc would be to write a grammar that understand something like: abstract Person { name : string ; spouse -> Person ? { year : integer } ; child -> Person * } (i.e. the same language with explicit nesting) and to write your own layout resolver to convert the "sweet" syntax to the one the parser will understand. (Note that I haven't actually tried this)

gdetrez commented 11 years ago

I'm closing the issue. Please re-open if you are not satisfied with the answer.