[antlr-interest] Lists. Lexer or Parser?
Johannes Luber
jaluber at gmx.de
Sat Sep 13 05:44:18 PDT 2008
Dave Pawson schrieb:
> 2008/9/13 Johannes Luber <jaluber at gmx.de>:
>> Dave Pawson schrieb:
>
>>> The input is
>>>
>>> blah
>>> blah
>>>
>>> *list item 1
>>> * list content 2
>> There is one. I'd define a grammar like:
>>
>> grammar Test;
>>
>> tokens {
>> LIST='LIST';
>> STAR=''*';
>> }
>>
>> CONTENT: ('a'..'z' | 'A'..'Z')+;
>> NEWLINE: '\r' | '\n';
>> WHITESPACE: ('\t' | ' ')+ {$channel = HIDDEN;};
>>
>> start: line*;
>>
>> line: content+ NEWLINE+
>> | STAR LIST content+ NEWLINE+
>> ;
>
>
> That requires the string 'LIST' on each list element?
'LIST' can be removed, if that bothers you.
> My input is line based plain text.
>
> A list starts from the first occurrence of
> * Any string content to end of line
>
> and ends on the last
> * Any string content up to end of line.
grammar Test;
tokens {
STAR=''*';
}
CONTENT: ~NEWLINE+; // possibly ~(NEWLINE|WHITESPACE)+
NEWLINE: '\r' | '\n';
WHITESPACE: ('\t' | ' ')+ {$channel = HIDDEN;};
start: line*;
line: content+ NEWLINE+
| STAR content+ NEWLINE+
;
You can add actions which determine the beginning and the end of the list.
Johannes
>
> I guess I can leave this one till I've read more about navigating trees.
>
> regards
>
>
More information about the antlr-interest
mailing list