Hello. I’m trying to implement a simple AST interpreter in Crystal. I need a Token class. My current attempt at writing it looks like this:
class Token getter type : TokenType getter literal getter lexeme : String getter line : Int32 def initialize(@type, @literal, @lexeme, @line) end end
The problem is that I don’t know what type I should use for the literal field. In theory, it should be possible to keep values of different types in it. In Java, there’s the Object class that can be used as an universal wrapper for instances of any classes. But in Crystal, Object works in a different way (if I understood it correctly).
So, what should I use instead?