[antlr-interest] gathering any character until specified char

gaoshang1999 gaoshang1999 at 163.com
Sat Aug 20 07:54:16 PDT 2011


Hi  Ben

I do a test  based your problem.  It runs perfectly well.  Here is what I've done.

//begin grammar
grammar Author;

options{
    output = AST;
    ASTLabelType = CommonTree;
}

tokens{
    AUTHORS;
}

authors
: auth+=UNTIL_SEPARATOR (SEPARATOR auth+=UNTIL_SEPARATOR)*
 -> ^(AUTHORS $auth*)
;

WS : (' ' |'\t' |'\r' |'\n' )+ {skip();} ;

SEPARATOR : ',' ;

UNTIL_SEPARATOR
: (~SEPARATOR)*
 ;
//end grammar


Here is a test by using the parser Antlr genereated. The AST is built successfully.

Input : Ben Corne , An antlr FAN, Gao ,  Another antlr FAN
(AUTHORS Ben Corne   An antlr FAN  Gao    Another antlr FAN)

Hope it will be helpful for you.


Best regards
Gao







At 2011-08-15 17:26:05,"Ben Corne" <ben.corne at gmail.com> wrote:
>Here's another try:
>authors
>: auth+=until_separator (',' auth+=until_separator)*
> -> ^(AGAUTHORS $auth)
>;
>
>until_separator
>: (~SEPARATOR)*
> ;
>
>SEPARATOR : ',' ;
>
>This results again in empty values.
>Is there an option I need to toggle to make sure the characters get
>accounted for?
>
>2011/8/14 Ben Corne <ben.corne at gmail.com>
>
>> HI all
>>
>> I'm trying to create a list of any characters but trailing whitespaces
>> separated by comma's.
>> Here are the rules for a specific case where I need this kind of list:
>>
>> authors
>> : (auth+=(.*)) WS* (',' WS* auth+=(.*) WS*)
>>  -> ^(AGAUTHORS $auth)
>> ;
>> WS  :   ( ' '
>>         | '\t'
>>         | '\r'
>>         | '\n'
>>         )
>>     ;
>>
>> Input: Ben Corne ,  An antlr FAN
>> Parse tree should look like this:
>> authors
>> |------------ 'Ben Corne'
>> |------------ WS
>> |------------ ','
>> |------------ WS
>> |------------ 'An antlr FAN'
>>
>> Instead I get one that doesn't seem to gather any character but the ','
>> (tested in debugger)
>> Anyone know what I'm doing wrong here?
>>
>> Kind regards
>> Ben Corne
>>
>
>List: http://www.antlr.org/mailman/listinfo/antlr-interest
>Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address


More information about the antlr-interest mailing list