utybo / Lixy

A Kotlin lexer framework with an easy-to-use DSL
Apache License 2.0
49 stars 0 forks source link

Add optional `name` property to `LixyGenericTokenType` #5

Closed Him188 closed 4 years ago

Him188 commented 4 years ago
class LixyGenericTokenType :
    LixyTokenType

fun tokenType(): LixyGenericTokenType =
    LixyGenericTokenType()

It will be very useful (especially for debugging) if LixyGenericTokenType can have a name. Also probably we can add a pretty toString or make it data class.

utybo commented 4 years ago

I would generally recommend against using the LixyGenericTokenType and tokenType() functions, but this can definitely be a nice addition!

The "cleaner" intended way of declaring token types would be to have an enum that implements the LixyTokenType and declare everything in there. Because this is "your" enum, you could also have additional information in there, making it a fairly flexible option. But you can't always declare enum classes (Kotlin scripts don't allow you to do that for some reason), so I agree that this would be very useful.