package minijava.lexer object Tokens { sealed abstract class TokenKind case object BAD extends TokenKind /* represents incorrect tokens. */ case object EOF extends TokenKind case object SEMICOLON extends TokenKind /* ; */ /* etc. */ case class ID(value: String) extends TokenKind /* Identifiers */ /* etc. */ /* A Token is a positional wrapper around a TokenKind */ class Token(val kind: TokenKind) extends Positional /* Used to create tokens by writing simply: Token(EOF), for instance */ object Token { def apply(kind: TokenKind): Token = new Token(kind) def unapply(token: Token): Option[TokenKind] = Some(token.kind) } }