[antlr-interest] Sometimes significant new lines

Iztok Kavkler iztok.kavkler at fmf.uni-lj.si
Fri May 8 02:11:08 PDT 2009


You can also check the example grammars for Python (newlines are 
significant, unless they appear within parenthases) and JavaScript (with 
quite complicated rules for when the newlines are significant).

When I was writing the parser for my DSL I checked the JavaScript 
solution, decided it's not worth the bother, and opted for Python 
version (it's quite easy, it only requires a bracket level counter in 
the lexer).


> I do actually want to allow new lines everywhere. I'm starting to
> think it's not worth the trouble of allowing them. Seems to make the
> grammar much more complicated for little benefit.
> 
> Thanks for your help,
> Nick
> 
> On Fri, May 8, 2009 at 10:38 AM, Iztok Kavkler
> <iztok.kavkler at fmf.uni-lj.si> wrote:
>> Since it appears that newlines can only appear between statements I would
>> recomend not sending them to the hidden channel but matching them like this:
>>
>> terminator: ';' NEWLINE* | NEWLINE+ | EOF;
>>
>> configItem: ID '=' VALUE terminator ;
>>
>> (You will have to also match NEWLINE* at the beginning of the script,
>> otherwise you will get errors for empty lines at the beginning.)
>>
>> Cheers, Iztok
>>



More information about the antlr-interest mailing list