SJW/src/Compiler.hs

34 lines
732 B
Haskell

{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
module Compiler (
main
) where
import Context (Contextual)
import Data.Text (Text, cons)
import qualified Data.Text as Text (concat)
import Module (Module(..))
indent :: [Text] -> [Text]
indent = fmap (cons '\t')
include :: Bool -> Module -> Text
include isMain (Module {imports, payload}) = Text.concat $
header isMain
: indent payload
++ footer isMain
where
header True = "(function() {\n"
header False = "modules[''] = (function() {\n"
footer True = ["})());"]
footer False = [
"})());"
, "Object.freeze(modules['']);"
]
scan :: Contextual ()
scan = undefined
main :: Contextual Text
main = undefined