module SExpr (SExpr(..), getSymbol, getInteger, getList, printTree) where
data SExpr = Value Int
| Symbol String
| List [SExpr]
deriving(Int -> SExpr -> ShowS
[SExpr] -> ShowS
SExpr -> String
(Int -> SExpr -> ShowS)
-> (SExpr -> String) -> ([SExpr] -> ShowS) -> Show SExpr
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> SExpr -> ShowS
showsPrec :: Int -> SExpr -> ShowS
$cshow :: SExpr -> String
show :: SExpr -> String
$cshowList :: [SExpr] -> ShowS
showList :: [SExpr] -> ShowS
Show, SExpr -> SExpr -> Bool
(SExpr -> SExpr -> Bool) -> (SExpr -> SExpr -> Bool) -> Eq SExpr
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: SExpr -> SExpr -> Bool
== :: SExpr -> SExpr -> Bool
$c/= :: SExpr -> SExpr -> Bool
/= :: SExpr -> SExpr -> Bool
Eq)
getSymbol :: SExpr -> Maybe String
getSymbol :: SExpr -> Maybe String
getSymbol (Value Int
_) = Maybe String
forall a. Maybe a
Nothing
getSymbol (List [SExpr]
_) = Maybe String
forall a. Maybe a
Nothing
getSymbol (Symbol String
s) = String -> Maybe String
forall a. a -> Maybe a
Just String
s
getInteger :: SExpr -> Maybe Int
getInteger :: SExpr -> Maybe Int
getInteger (Value Int
int) = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
int
getInteger (List [SExpr]
_) = Maybe Int
forall a. Maybe a
Nothing
getInteger (Symbol String
_) = Maybe Int
forall a. Maybe a
Nothing
getList :: SExpr -> Maybe [SExpr]
getList :: SExpr -> Maybe [SExpr]
getList (Value Int
_) = Maybe [SExpr]
forall a. Maybe a
Nothing
getList (List [SExpr]
l) = [SExpr] -> Maybe [SExpr]
forall a. a -> Maybe a
Just [SExpr]
l
getList (Symbol String
_) = Maybe [SExpr]
forall a. Maybe a
Nothing
printTree :: SExpr -> Maybe String
printTree :: SExpr -> Maybe String
printTree SExpr
s = String -> Maybe String
forall a. a -> Maybe a
Just (SExpr -> String
forall a. Show a => a -> String
show SExpr
s)