-- Copyright (C) 2018-2024 Jun Zhang <zhangjunphy[at]gmail[dot]com>
--
-- This file is a part of decafc.
--
-- decafc is free software: you can redistribute it and/or modify it under the
-- terms of the MIT (X11) License as described in the LICENSE file.
--
-- decafc is distributed in the hope that it will be useful, but WITHOUT ANY
-- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
-- FOR A PARTICULAR PURPOSE.  See the X11 license for more details.

-- Lexer tokens
module Lexer.Token (Token(..)) where

import Data.Text (Text)

-- | Lexer tokens.
data Token = Keyword !Text
           | Identifier !Text
           | CharLiteral !Text
           | IntLiteral !Text
           | BooleanLiteral !Text
           | StringLiteral !Text
           | AssignOp
           | CompoundAssignOp !Text
           | IncrementOp !Text
           | ArithmeticOp !Text
           | RelationOp !Text
           | EquationOp !Text
           | ConditionOp !Text
           | LCurly
           | RCurly
           | LParen
           | RParen
           | LBrack
           | RBrack
           | Choice
           | Colon
           | Semicolon
           | Comma
           | Negate
           | EOF
           deriving (Token -> Token -> Bool
(Token -> Token -> Bool) -> (Token -> Token -> Bool) -> Eq Token
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Token -> Token -> Bool
== :: Token -> Token -> Bool
$c/= :: Token -> Token -> Bool
/= :: Token -> Token -> Bool
Eq)

instance Show Token where
  show :: Token -> String
show (Keyword Text
k) = Text -> String
forall a. Show a => a -> String
show Text
k
  show (Identifier Text
s) = String
"IDENTIFIER " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
s
  show (CharLiteral Text
s) = String
"CHARLITERAL " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
s
  show (IntLiteral Text
s) = String
"INTLITERAL " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
s
  show (BooleanLiteral Text
s) = String
"BOOLEANLITERAL " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
s
  show (StringLiteral Text
s) = String
"STRINGLITERAL " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Text -> String
forall a. Show a => a -> String
show Text
s
  show Token
AssignOp = String
"="
  show (IncrementOp Text
s) = Text -> String
forall a. Show a => a -> String
show Text
s
  show (CompoundAssignOp Text
s) = Text -> String
forall a. Show a => a -> String
show Text
s
  show (ArithmeticOp Text
s) = Text -> String
forall a. Show a => a -> String
show Text
s
  show (RelationOp Text
s) = Text -> String
forall a. Show a => a -> String
show Text
s
  show (EquationOp Text
s) = Text -> String
forall a. Show a => a -> String
show Text
s
  show (ConditionOp Text
s) = Text -> String
forall a. Show a => a -> String
show Text
s
  show Token
LCurly = String
"{"
  show Token
RCurly = String
"}"
  show Token
LParen = String
"("
  show Token
RParen = String
")"
  show Token
LBrack = String
"["
  show Token
RBrack = String
"]"
  show Token
Choice = String
"?"
  show Token
Colon = String
":"
  show Token
Semicolon = String
";"
  show Token
Comma = String
","
  show Token
Negate = String
"!"
  show Token
EOF = String
"EOF"