module Language.Sexp.Types
  ( Atom (..)
  , Kw (..)
  , Sexp (..)
  , Position (..)
  , dummyPos
  , getPos
  ) where
import Data.Scientific
import Data.Text (Text)
import Text.PrettyPrint.Leijen.Text (Pretty (..), int, colon, (<>))
data Position =
  Position  !Int  !Int
  deriving (Show, Ord, Eq)
dummyPos :: Position
dummyPos = Position 0 0
instance Pretty Position where
  pretty (Position line col) = int line <> colon <> int col
newtype Kw = Kw { unKw :: Text }
  deriving (Show, Eq, Ord)
data Atom
  = AtomBool Bool
  | AtomInt Integer
  | AtomReal Scientific
  | AtomString Text
  | AtomSymbol Text
  | AtomKeyword Kw
    deriving (Show, Eq, Ord)
data Sexp
  = Atom    !Position !Atom
  | List    !Position [Sexp]
  | Vector  !Position [Sexp]
  | Quoted  !Position Sexp
    deriving (Show, Eq, Ord)
getPos :: Sexp -> Position
getPos (Atom p _)   = p
getPos (Quoted p _) = p
getPos (Vector p _) = p
getPos (List p _)   = p