grammatica-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Grammatica-users] Constructing a new-line sensitive grammar.


From: Per Cederberg
Subject: Re: [Grammatica-users] Constructing a new-line sensitive grammar.
Date: Wed, 19 Sep 2007 22:06:54 +0200
User-agent: Thunderbird 2.0.0.6 (Macintosh/20070728)

I think the problem is that the newline sequence in
Windows is \r\n and not the other way around. But
you could support both:

NEWLINE    = <<\n\r|\r\n|[\n\r]>>

Or if you don't care about the number of newlines
at all:

NEWLINE    = <<[\n\r]+>>

Hope this helps!

/Per

[ICR] wrote:
I'm fairly new to writing grammar files. I have succeeded in writing a grammar file that seems to parse correctly, however I want to adapt it to be sensitive to newlines. Below is a simplified version of my grammar file:

%header%
GRAMMARTYPE    = "LL"
%tokens%
ENTRY           = "$entry"
IDENT            = <<[a-zA-Z0-9_-]+>>
WHITESPACE     = <<[ \t]+>> %ignore%
%productions%
File                  = EntryStatement Pairing ;
EntryStatement = ENTRY IDENT ;
Pairing              = IDENT IDENT [Pairing] ;

I have tried the following and variations, but they do not seem to work:

%header%
GRAMMARTYPE    = "LL"
%tokens%
NEWLINE    = <<\n\r|[\n\r]>>
ENTRY         = "$entry"
IDENT          = <<[a-zA-Z0-9_-]+>>
WHITESPACE     = <<[ \t]+>> %ignore%
%productions%
File                  = EntryStatement NEWLINE Pairing ;
EntryStatement = ENTRY IDENT ;
Pairing              = IDENT IDENT [NEWLINE Pairing] ;

But I get the error:

unexpected token "\r" <NEWLINE>, expected < IDENT>, on line: 1 column: 13
unexpected token "(...)" <NEWLINE>, expected < IDENT>, on line: 2 column: 13 unexpected token "(...)" <NEWLINE>, expected < IDENT>, on line: 4 column: 13
etc.

on the input:
$entry TESTA
TESTA TESTB
TESTB TESTC
TESTC TESTD
etc.


_______________________________________________
Grammatica-users mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/grammatica-users






reply via email to

[Prev in Thread] Current Thread [Next in Thread]