[antlr-interest] proposal: new properties or Token methods
    Terence Parr 
    parrt at cs.usfca.edu
       
    Fri Dec 28 13:46:57 PST 2007
    
    
  
On Dec 28, 2007, at 1:37 PM, Johannes Luber wrote:
> Terence Parr schrieb:
>> hi. I find myself doing Integer.valueOf($label.text) a lot.  Integer
>> values are so common in languages that perhaps we should define
>> $label.int and maybe label.float?  Or, is it simpler to just define
>>
>>    public int toInt();
>>    public float toFloat();
>>    public double toDouble();
>>
>> in Token interface?  I guess I'll try that first.
>
> Adding properties to labels seems to be less language-dependent.
Agreed but I don't want to add lots of more templates...well, let's  
start with just int:
tokenLabelPropertyRef_int(scope,attr) ::= "(<scope>!=null? 
Integer.valueOf(<scope>.getText()):0)"
lexerRuleLabelPropertyRef_int(scope,attr) ::=
     "(<scope>!=null?Integer.valueOf(<scope>.getText()):0)"
lexerRulePropertyRef_int(scope,attr) ::=  
"Integer.valueOf(<scope>.getText())"
> So I'd
> prefer this approach. BTW, what is supposed to happen, when the label
> contains "abc" instead?
Whatever the native implementation says happens when converting "abc"  
to int.
Ok, let's try this new .int property.  Seems very useful.
Ter
    
    
More information about the antlr-interest
mailing list