S-expressions: Difference between revisions

Content added Content deleted
Line 3,035: Line 3,035:
import Data.Tree (Tree (..), drawForest)
import Data.Tree (Tree (..), drawForest)


------------------------ DATA TYPES ----------------------
------------------------ DATA TYPE -----------------------


data Val
data Val
Line 3,044: Line 3,044:
| List [Val]
| List [Val]
deriving (Eq, Show, Read)
deriving (Eq, Show, Read)

instance Semigroup Val where
(<>) (List a) (List b) = List (a <> b)

instance Monoid Val where
mempty = List []


--------------------------- MAIN -------------------------
--------------------------- MAIN -------------------------
Line 3,086: Line 3,080:


atom :: String -> Val
atom :: String -> Val
atom [] = mempty
atom [] = List []
atom s@('"' : _) =
atom s@('"' : _) =
fromMaybe mempty (maybeRead ("String " <> s))
fromMaybe (List []) (maybeRead ("String " <> s))
atom s = firstParse parses
atom s = firstParse parses
where
where
firstParse [] = mempty
firstParse [] = List []
firstParse (x : _) = x
firstParse (x : _) = x
parses =
parses =