[antlr-interest] Java string array issue in v3.

Kay Roepke kroepke at classdump.org
Sat Jun 16 05:39:17 PDT 2007


Hi!

On Jun 15, 2007, at 11:35 PM, Johannes Luber wrote:

> Ted Villalba wrote:
>> Hi.
>> Not sure, I might be doing something wrong here, but this seems  
>> like a bug.
>> I'm trying to pass a string array to the start of my tree, but when I
>> compile my tree grammar the String array gets compiled
>> into a String.
>> So in treeGrammar.g my start symbol is rule "start"
>>
>> start[HashMap fieldMap, String[] fqls]
>> @init{
>> etc etc...
>> }
>
> IIRC, the problem is that arrays rely on "[]" which are part of the
> ANTLR grammar and that this is falsely attributed to be a parameter  
> for
> a rule. As far as I know there is no way to prevent this behaviour  
> right
> now. A workaround would be to declare flqs as object and cast it in  
> Java
> to a String array.

Yes, that's correct. As it stands it is not possible to escape the []  
chars.
I just had a look at the grammar and have a simple fix for this case,  
i.e.
it should treat a bare '[]' as just that token without trying to  
match an argument.
I'm not, however, certain that this actually is a good idea, because I'm
unsure whether or not it breaks other things.

We should ask Ter if he's alright with it, after that I could push  
the fix.
In the meantime I added a bug and will attach the diff over at
<http://www.antlr.org:8888/browse/ANTLR-140>

Thanks for reporting this!

cheers,
-k
-- 
Kay Röpke
http://classdump.org/






More information about the antlr-interest mailing list