Skip to content
Snippets Groups Projects
Commit a541b45e authored by Daniel Firth's avatar Daniel Firth
Browse files

ShellRC: mostly OK AST printing

parent 956e9991
Branches
No related merge requests found
...@@ -20,6 +20,7 @@ import Brick (BrickEvent (VtyEvent), EventM, ...@@ -20,6 +20,7 @@ import Brick (BrickEvent (VtyEvent), EventM,
hBox, halt, on, padLeftRight, txt, hBox, halt, on, padLeftRight, txt,
vScrollBy, viewport, viewportScroll, vScrollBy, viewport, viewportScroll,
visible, withAttr) visible, withAttr)
import GHC.Exts
import qualified Brick import qualified Brick
import Brick.Widgets.Border import Brick.Widgets.Border
import qualified Brick.Widgets.List as Brick import qualified Brick.Widgets.List as Brick
...@@ -249,40 +250,88 @@ readDerivation (MkPackagesDir d) (MkName x) = do ...@@ -249,40 +250,88 @@ readDerivation (MkPackagesDir d) (MkName x) = do
q <- B.readFile $ toFilePath j q <- B.readFile $ toFilePath j
pure $ T.decodeUtf8Lenient q pure $ T.decodeUtf8Lenient q
callHackageLit :: Expr Src Import horizonField :: Text -> Expr s a
callHackageLit = Field "H" (FieldSelection Nothing "callHackage" Nothing) horizonField = Field (horizonSpecIdentifier) . makeFieldSelection
callGitLit :: Expr Src Import callHackageLit :: Expr s a
callGitLit = Field "H" (FieldSelection Nothing "callGit" Nothing) callHackageLit = horizonField "callHackage"
callHackageApp :: Name -> Version -> Expr Src Import callGitLit :: Expr s a
callHackageApp (MkName x) (MkVersion v) = App (App callHackageLit (TextLit $ Chunks [] x)) (TextLit $ Chunks [] v) callGitLit = horizonField "callGit"
callGitApp :: Repo -> Revision -> Expr Src Import callTarballLit :: Expr s a
callGitApp (MkRepo (MkUrl x)) (MkRevision v) = App (App callGitLit (TextLit $ Chunks [] x)) (TextLit $ Chunks [] v) callTarballLit = horizonField "callTarball"
callHackageApp :: HackageSource -> Expr s a
callHackageApp (MkHackageSource (MkName x) (MkVersion v)) = App (App callHackageLit (TextLit $ Chunks [] x)) (TextLit $ Chunks [] v)
f :: Name -> HaskellPackage -> (Name, RecordField Src Import) callGitApp :: GitSource -> Expr s a
f x k = case source k of callGitApp (MkGitSource (MkRepo (MkUrl x)) (MkRevision v) _) = App (App callGitLit (TextLit $ Chunks [] x)) (TextLit $ Chunks [] v)
FromHackage (MkHackageSource n v) -> (x, RecordField Nothing (callHackageApp n v) Nothing Nothing)
FromGit (MkGitSource n v _) -> (x, RecordField Nothing (callGitApp n v) Nothing Nothing)
g :: IO (Expr Src Import) callTarballApp :: TarballSource -> Expr s a
g = do callTarballApp (MkTarballSource (MkUrl x)) = App callTarballLit (TextLit $ Chunks [] x)
x <- Dhall.inputFile @HorizonExport Dhall.auto "horizon.dhall"
pure $ h x
haskellSourceToExpr :: HaskellSource -> Expr s a
haskellSourceToExpr k = case k of
FromHackage x -> callHackageApp x
FromGit x -> callGitApp x
FromTarball x -> callTarballApp x
cabalFlagToExpr :: CabalFlag -> Expr s a
cabalFlagToExpr (MkCabalFlag x) =
let (z, t) = case x of
Disable a -> (makeFieldSelection "Disable", a)
Enable a -> (makeFieldSelection "Enable", a)
in App (Field (horizonField "CabalField") z) (TextLit $ Chunks [] t)
haskellPackageToExpr :: HaskellPackage -> Expr s a
haskellPackageToExpr (MkHaskellPackage s xs ys) =
let t = haskellSourceToExpr s
applyFlagsExpr = if (not . null $ ys) then \x -> With x (WithLabel "flags" :| []) (ListLit Nothing $ GHC.Exts.fromList $ map cabalFlagToExpr ys) else id
in applyFlagsExpr t
packageListToExpr :: PackageList -> Expr s a
packageListToExpr (MkPackageList (Map.toList -> ys)) = RecordLit . DMap.fromList . map (\(MkName x, y) -> (x, makeRecordField $ haskellPackageToExpr y)) $ ys
h :: HorizonExport -> Expr Src Import h :: HorizonExport -> Expr Src Import
h (MakePackageSet (MkPackageSetExportSettings d _ (MkPackageSet _ (MkPackageList (Map.toList -> ys))))) = h (MakePackageSet (MkPackageSetExportSettings (MkPackagesDir d) (MkPackageSetFile f) (MkPackageSet (MkCompiler c) xs))) = letHorizonSpecIn $ letPackagesBindingIn xs $ RecordLit . DMap.fromList $ [
RecordLit $ DMap.fromList $ map ((\(MkName x, y) -> (x, y)) . uncurry f) ys ("packageSetFile", makeRecordField $ TextLit $ Chunks [] (T.pack $ toFilePath f)),
("packagesDir", makeRecordField $ TextLit $ Chunks [] $ T.pack $ toFilePath d),
("packagesSet", makeRecordField $ RecordLit $ DMap.fromList [("compiler", makeRecordField $ TextLit $ Chunks [] c), ("packages", makeRecordField $ ToMap "packages" Nothing)])]
loadHorizon :: IO HorizonExport loadHorizon :: IO HorizonExport
loadHorizon = Dhall.inputFile @HorizonExport Dhall.auto "horizon.dhall" loadHorizon = Dhall.inputFile @HorizonExport Dhall.auto "horizon.dhall"
horizonSpecUrl :: Dhall.Core.URL
horizonSpecUrl = Dhall.Core.URL HTTPS "" (Dhall.Core.File (Dhall.Core.Directory ["dhall", "0.6", "raw", "-", "horizon-spec", "horizon", "gitlab.homotopic.tech"]) "package.dhall") Nothing Nothing
horizonSpecImportHashed :: ImportHashed
horizonSpecImportHashed = ImportHashed Nothing (Remote horizonSpecUrl)
horizonSpecImport :: Import
horizonSpecImport = Import horizonSpecImportHashed Code
horizonSpecIdentifier :: Expr s a
horizonSpecIdentifier = "H"
packagesIdentifier :: Text
packagesIdentifier = "packages"
horizonSpecBinding :: Binding s Import
horizonSpecBinding = makeBinding "H" (Dhall.Core.Embed horizonSpecImport)
letHorizonSpecIn :: Expr s Import -> Expr s Import
letHorizonSpecIn = Let horizonSpecBinding
packagesBinding :: PackageList -> Binding s a
packagesBinding = makeBinding packagesIdentifier . packageListToExpr
letPackagesBindingIn :: PackageList -> Expr s a -> Expr s a
letPackagesBindingIn xs = Let (packagesBinding xs)
go :: IO () go :: IO ()
go = do go = do
x <- Dhall.inputFile @HorizonExport Dhall.auto "horizon.dhall" x <- loadHorizon
k <- buildCursor x k <- buildCursor x
Brick.defaultMain packageListMain $ MkHorizonTUIState k Nothing Brick.defaultMain packageListMain $ MkHorizonTUIState k Nothing
pure () pure ()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment