[antlr-interest] Grammar definition problem
leiche im teich
leicheimteich at googlemail.com
Thu Feb 5 13:09:04 PST 2009
Hello,
I'm a ANTLR newbie and have a problem to define the right grammar for the
following input.
- one input line is one record
- the structure is: <fieldname> <one colon followed by one or more spaces as
delimiter> <fieldvalue> <newline>*
- the fieldnames are known
My problem is, than the fieldvalue can have colon or space characters too.
This is my grammar:
grammar Foo;
options {
output=AST;
ASTLabelType=CommonTree;
}
entry : fieldname FIELDSEPERATOR fieldvalue '\n'*
;
fieldvalue : ID
;
fieldname: NAME
|GIVENNAME
|STREET
|ZIP
|CITY
|COUNTRY
|TEXT
;
NAME : 'Name';
GIVENNAME : 'Givenname';
STREET : 'Street';
ZIP : 'Zip';
CITY : 'City';
COUNTRY : 'Country';
TEXT : 'Text';
FIELDSEPERATOR : ':' ' '+
;
ID : AllowedChars+
;
fragment
AllowedChars : 'A'..'Z'
| 'a'..'z'
| '0'..'9'
| '+'
| '-'
| ' '
// | ':'
| '#'
| '.'
;
If i try the input "Text: Free Text with # sign" it works. But if i do
not comment the ':' in the AllowedChars and try the input "Text: Free
Text with : sign" it goes wrong :-(
How can i solve this problem????
Thank's
Matthias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090205/7b0e8032/attachment.html
More information about the antlr-interest
mailing list