Skip to content

Commit

Permalink
v0.5.0: Nested Actions Now Executed and Major Refactoring (#123)
Browse files Browse the repository at this point in the history
* Add missing GHC options

* Remove record from core

* Remove

* Reexport Show

* Add scaffolding for HTTP

* wip

* wip

* Update

* Refactor

* update

* Update

* Change to fmt strings

* Add toml

* wip

* wip

* OMG IT WORKZ!!1!!one!

* Put back HTTP

* Bump versions

---------

Co-authored-by: Nikita Tchayka <[email protected]>
  • Loading branch information
Nick Seagull and Nikita Tchayka authored Sep 16, 2024
1 parent 714a27c commit deb9780
Show file tree
Hide file tree
Showing 37 changed files with 639 additions and 487 deletions.
8 changes: 2 additions & 6 deletions cli/nhcli.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.4
name: nhcli
version: 0.3.1
version: 0.5.0
synopsis: Command Line Tool for NeoHaskell
-- description:
homepage: https://neohaskell.org
Expand All @@ -15,7 +15,6 @@ build-type: Simple
common common_cfg
ghc-options: -Wall
-Werror
-fplugin=Data.Record.Anon.Plugin
-threaded
default-extensions:
ApplicativeDo
Expand All @@ -32,8 +31,6 @@ common common_cfg
OverloadedLists
OverloadedLabels
OverloadedRecordDot
OverloadedRecordUpdate
RebindableSyntax
DuplicateRecordFields
PackageImports
NamedFieldPuns
Expand All @@ -42,12 +39,12 @@ common common_cfg

build-depends:
nhcore,
large-anon,

library
import: common_cfg
exposed-modules:
Neo,
Neo.Build,
-- other-modules:
-- other-extensions:
hs-source-dirs: src
Expand All @@ -62,7 +59,6 @@ executable neo
nhcli
ghc-options: -Wall
-Werror
-fplugin=Data.Record.Anon.Plugin
hs-source-dirs: app
default-language: GHC2021

Expand Down
95 changes: 35 additions & 60 deletions cli/src/Neo.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,82 +5,50 @@ import Array (Array)
import Array qualified
import Command qualified
import Core
import Path qualified
import Neo.Build qualified as Build
import Service qualified
import ToText (Show (..))


type State =
Record
'[ "foo" := Text,
"bar" := Text
]
data State = State
{ build :: Build.State
}
deriving (Show, Eq, Ord)


data Event
= Transpile TranspilationStartedEvent
= Build Build.Event
| NoOp
deriving (Show, Eq, Ord)


type TranspilationStartedEvent =
Record
'[ "inputPath" := Path,
"outputPath" := Path
]


commandParser :: Command.OptionsParser Event
commandParser = do
let transpile =
ANON
{ name = "transpile",
description = "Transpile a file or directory",
let build =
Command.CommandOptions
{ name = "build",
description = "build a file or directory",
version = Nothing,
decoder = transpileParser
decoder = buildParser
}
Command.commands
(Array.fromLinkedList [transpile])

(Array.fromLinkedList [build])

transpileParser :: Command.OptionsParser Event
transpileParser = do
event <- transpilationParser
pure (Transpile event)


transpilationParser :: Command.OptionsParser TranspilationStartedEvent
transpilationParser = do
inputPath <-
Command.path
ANON
{ help = "Path to the input file or directory",
long = "input",
short = 'i',
metavar = "PATH"
}

outputPath <-
Command.path
ANON
{ help = "Path to the output file or directory",
long = "output",
short = 'o',
metavar = "PATH"
}

pure ANON {inputPath = inputPath, outputPath = outputPath}
buildParser :: Command.OptionsParser Event
buildParser = do
event <- Build.commandParser
pure (Build event)


init :: (State, Action Event)
init = do
let emptyState = ANON {foo = "foo", bar = "bar"}
let emptyState = State {build = Build.initialState}
let action =
Command.parse
ANON
Command.CommandOptions
{ name = "neo",
description = "NeoHaskell's console helper",
version = Just [version|0.0.0|],
version = Just [version|0.5.0|],
decoder = commandParser
}
(emptyState, action)
Expand All @@ -89,9 +57,10 @@ init = do
update :: Event -> State -> (State, Action Event)
update event state =
case event of
Transpile transpilationStartedEvent -> do
let newState = state {foo = "Transpilation started", bar = transpilationStartedEvent.inputPath |> Path.toText}
let action = Action.none
Build buildEvent -> do
let (newBuildState, buildAction) = Build.update buildEvent state.build
let newState = state {build = newBuildState}
let action = buildAction |> Action.map Build
(newState, action)
NoOp -> do
let newState = state
Expand All @@ -100,16 +69,22 @@ update event state =


view :: State -> Text
view _ = "Hello, world!"
view s =
if s.build.message == ""
then "Loading"
else s.build.message


triggers :: Array (Trigger Event)
triggers = Array.empty


main :: IO ()
main = do
let app :: Service.UserApp State Event
app =
ANON {init = init, view = view, triggers = triggers, update = update}
Service.init app
main =
Service.run
Service.UserApp
{ init = init,
view = view,
triggers = triggers,
update = update
}
66 changes: 66 additions & 0 deletions cli/src/Neo/Build.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
module Neo.Build (
Event,
BuildEvent (..),
State (..),
commandParser,
initialState,
update,
view,
) where

import Action qualified
import Command qualified
import Core
import File qualified


type Event = BuildEvent


data BuildEvent
= BuildStarted
| ProjectFileNotFound
| ReadProjectFile Text
deriving (Show, Eq, Ord)


commandParser :: Command.OptionsParser BuildEvent
commandParser = do
pure BuildStarted


data State = State
{ message :: Text
}
deriving (Show, Eq, Ord)


initialState :: State
initialState =
State
{ message = "Build Started"
}


update :: BuildEvent -> State -> (State, Action BuildEvent)
update event state =
case event of
BuildStarted -> do
let handleRes res = case res of
Ok text -> ReadProjectFile text
Err _ -> ProjectFileNotFound
let opts =
File.ReadOptions
{ path = "foo.txt"
}
(state, File.readText opts |> Action.map handleRes)
ReadProjectFile text -> do
let newState = state {message = text}
(newState, Action.none)
ProjectFileNotFound -> do
let newState = state {message = "Project file not found"}
(newState, Action.none)


view :: State -> View
view = dieWith "Not implemented yet"
102 changes: 0 additions & 102 deletions cli/src/Neo/Transpile.hs

This file was deleted.

1 change: 1 addition & 0 deletions core/concurrency/AsyncIO.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Basics
import Control.Concurrent qualified as Ghc
import Control.Concurrent.Async qualified as GhcAsync
import Data.Either qualified as Either
import IO (IO)
import Result (Result)
import Result qualified

Expand Down
Loading

0 comments on commit deb9780

Please sign in to comment.