[antlr-interest] Question about CommonTokens in Java Hashmaps

Joachim Lusiardi joachim at lusiardi.de
Fri Jun 26 09:29:57 PDT 2009


Hi again,
I derived my own token class from CommonToken fitting my needs. Now i
wonder how i can get the lexer to use my class instead of CommonToken. I
assume i should derive my own lexer and use the superclass option?
Best greetings
Joachim Lusiardi

Jim Idle schrieb:
> Derive your own token from CommonToken and use that as the token type.
> 
> Jim
> 
> On Jun 25, 2009, at 9:51 AM, Joachim Lusiardi <joachim at lusiardi.de> wrote:
> 
>> Hi,
>> i have short question about org.antlr.runtime.Token instances in Java
>> standard collections. Since (as far as i can see from the source) the
>> mentioned class does not override hashCode and equals i have troubles to
>> use this with standard containers like HashMap or Vector.
>>
>> What can i do to solve this problem? I expected that 2 CommonToken
>> objects have the same tokenindex, start, stop, text, type, channel, line
>> and charPosition in line they should be equal? and the hashCode also
>> should be derived from this?
>>
>> Best greetings
>> Joachim Lusiardi
>>
>> 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