I asked one of the BNFC developers and quoted his answer here:
Space characters, such as newlines, are not supported in tokens because BNFC has a hard conductor such as lexer "space". The idea is that spaces cannot carry meaning into “well-behaved” languages. One of these limitations is what made BNFC so simple ... but you have to solve it using a preprocessor, for example. parsing input line by line.
Such as:
entrypoints File ; comment "#" ; token ID ( letter | digit | ["-_'"] )+ ; Ini. File ::= [Section] ; Sect. Section ::= "[" ID "]" [Statement] ; Bind. Statement ::= ID "=" ID ; separator Statement "//" ; terminator Section "//" ;
Reading:
[name] x = 10 y = 20
Preprocess:
[name]
Analyze:
Ini [Sect (ID "name") [Bind (ID "x") (ID "10"), Bind (ID "y") (ID "20")]]
Transform:
↓ ↓ Ini [Sect (ID "name") [Bind (ID "x") (ID "0"), Bind (ID "y") (ID "0")]]
Record:
[name]
post processing:
[name] x = 0 y = 0
(not tested, don't know if it works, just to give an idea!)
Cetin sert
source share