tags:

views:

24

answers:

2

Let me make this clear, I have this enum:

enum Token {
    Number(v:Float);
    Identifier(v:String);
    TString(v:String);
    Var;
    Assign;
    Division;
    // and so on
}

I want to check if the value of a variable is an Identifier, but this doesn't work:

if(tk == Token.Identifier) {

It only allows me to compare the values if I pass arguments:

if(tk == Token.Identifier('test')) {

But this will only match if the identifier is 'test', but I want to match any identifier.

+1  A: 
Type.enumConstructor(tk) == "Identifier"

Read the Type doc for more methods on enum.

Andy Li
Thanks! //15 chars
M28
+1  A: 

alternatively:

static function isIdentifier(token : Token) return switch(token) { case Token.Identifier(_): true; default: false; }

Using "using" you should also be able to do:

if(tk.isIdentifier) {
Franco Ponticelli