module Cookbook.Project.Quill2.Q2Parse where
import qualified Cookbook.Essential.Continuous as Ct
import qualified Cookbook.Ingredients.Lists.Modify as Md
import qualified Cookbook.Ingredients.Lists.Access as Ac
import qualified Cookbook.Ingredients.Lists.Encompass as En
import Cookbook.Project.Quill2.Q2Prelude
decomment :: String -> String
decomment = (`Ct.splice` ("/*", "*/"))
prepare :: [String] -> String
prepare = decomment . (`Ct.remove` '\n') . unlines
pTable :: String -> Quill
pTable x = typ
where
name = Ct.between (Ct.before x '{') ('(',')')
typ = (name,if Ct.before x '{' `Ac.contains` "table" then Table (parseTables body) else List body)
body = Md.splitOn (En.encompassing x ('{','}')) ';'
quoted y = if ('`','\'') `Ac.surrounds` y then En.encompassing x ('`','\'') else Ct.remove y ' '
parseTables = map (\y -> (quoted $ Ct.before y ':', Ct.after y ':'))
pFile :: [String] -> [Quill]
pFile x = map pTable $ Md.splitOn (prepare x) '}'