module LoxTypes where import Prelude hiding (False, True) data CharToken = LeftParen | RightParen | LeftBrace | RightBrace | Comma | Dot | Minus | Plus | Semicolon | Slash | Star deriving (Eq) instance Show CharToken where show LeftParen = "(" show RightParen = ")" show LeftBrace = "{" show RightBrace = "}" show Comma = "," show Dot = "." show Minus = "-" show Plus = "+" show Semicolon = ";" show Slash = "/" show Star = "*" data MultiCharToken = Bang | BangEqual | Equal | EqualEqual | Greater | GreaterEqual | Less | LessEqual deriving (Eq) instance Show MultiCharToken where show Bang = "!" show BangEqual = "!=" show Equal = "=" show EqualEqual = "==" show Greater = ">" show GreaterEqual = ">=" show Less = "<" show LessEqual = "<=" data Keywords = And | Class | Else | False | Func | For | If | Nil | Or | Print | Return | Super | This | True | Var | While deriving (Eq) instance Show Keywords where show And = "and" show Class = "class" show Else = "else" show False = "false" show Func = "fun" show For = "for" show If = "if" show Nil = "nil" show Or = "or" show Print = "print" show Return = "return" show Super = "super" show This = "this" show True = "true" show Var = "var" show While = "while" data Literal = Identifier Keywords | Str String | Number Double deriving (Eq, Show) data LoxToken = Char CharToken | Op MultiCharToken | Lit Literal | Eof deriving (Eq, Show) -- This is how Class Token is defined in Crafting Interpreters but we will -- make use of the State in Megaparsec to report errors. -- data LoxToken = Token -- { tokenType :: TokenType, -- lexeme :: Text, -- literal :: Literal, -- line :: Int -- } -- deriving (Eq) -- -- instance Show LoxToken where -- show (Token tokenType lexeme literal _) = show tokenType ++ " " ++ show lexeme ++ " " ++ show literal