[antlr-interest] Matching empty string

Dukie Banderjee dukie_banderjee at hotmail.com
Sun Jun 14 20:09:31 PDT 2009


Hi,
My grammar needs to handle the following situation: A line can have multiple fields, separated by a delimiter. A field can have multiple components, separated by another delimiter.
If a field or component is blank, it should be counted as a blank field or blank component. For example with field delimiter '+' and component delimiter ':' :
UNB++::+123
is a 'UNB' line with 3 fields. The first field is blank, the second field has 3 blank components, and the last field has a single component with the value '123'.

Here is my grammar so far:

line         : TEXT fields ;
fields        : field* terminator! ;
field        : SEP t=fieldText? -> ^(FIELD $t?) ;
fieldText    : comp (CSEP comp)* ;
comp        : t=TEXT -> ^(COMP $t) ;

When a field is blank, e.g. '++', this correctly generates a ^(FIELD) with no children. However, I don't know how to get similar behaviour for the components, because whereas a field starts with a SEP and optional TEXT, the component may or may not have a leading CSEP. 

When the input is '+::+', there are three components, but the first is entirely blank, an empty string. 

What I would like is that '+::+' creates ^(FIELD ^(COMP) ^(COMP) ^(COMP)). How can I accomplish this?

Thanks,

Rob

_________________________________________________________________
Windows Live helps you keep up with all your friends, in one place.
http://go.microsoft.com/?linkid=9660826
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090614/e8cb385c/attachment.html 


More information about the antlr-interest mailing list