module Language.Sexp.Types
( Atom (..)
, Kw (..)
, Sexp (..)
, Position (..)
, dummyPos
, getPos
) where
import Data.Scientific
import Data.Text (Text)
import Data.Text.Prettyprint.Doc (Pretty (..), colon, (<>))
data Position =
Position !FilePath !Int !Int
deriving (Show, Ord, Eq)
dummyPos :: Position
dummyPos = Position "<no location information>" 1 0
instance Pretty Position where
pretty (Position fn line col) =
pretty fn <> colon <> pretty line <> colon <> pretty 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