Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved errors for nockma eval #2585

Merged
merged 6 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions app/Commands/Dev/Nockma/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Data.String.Interpolate (__i)
import Juvix.Compiler.Nockma.Evaluator (NockEvalError, evalRepl, fromReplTerm, programAssignments)
import Juvix.Compiler.Nockma.Evaluator.Options
import Juvix.Compiler.Nockma.Language
import Juvix.Compiler.Nockma.Pretty (ppPrint)
import Juvix.Compiler.Nockma.Pretty
import Juvix.Compiler.Nockma.Pretty qualified as Nockma
import Juvix.Compiler.Nockma.Translation.FromSource (parseProgramFile, parseReplStatement, parseReplText, parseText)
import Juvix.Parser.Error
Expand Down Expand Up @@ -110,14 +110,20 @@ direction' s = Repline.dontCrash $ do
liftIO (putStrLn (ppPrint p))

readTerm :: String -> Repl (Term Natural)
readTerm s = return (fromMegaParsecError (parseText (strip (pack s))))
readTerm = return . fromMegaParsecError . parseText . strip . pack

readReplTerm :: String -> Repl (Term Natural)
readReplTerm s = do
mprog <- getProgram
let t = run $ runError @NockEvalError (fromReplTerm (programAssignments mprog) (fromMegaParsecError (parseReplText (strip (pack s)))))
let t =
run
. runError @(NockEvalError Natural)
. fromReplTerm (programAssignments mprog)
. fromMegaParsecError
. parseReplText
$ strip (pack s)
case t of
Left e -> error (show e)
Left e -> error (ppTrace e)
Right tv -> return tv

readStatement :: String -> Repl (ReplStatement Natural)
Expand All @@ -137,12 +143,12 @@ evalStatement = \case
. runM
. runReader defaultEvalOptions
. runError @(ErrNockNatural Natural)
. runError @NockEvalError
. runError @(NockEvalError Natural)
$ evalRepl (putStrLn . Nockma.ppTrace) prog s t
case et of
Left e -> error (show e)
Right ev -> case ev of
Left e -> error (show e)
Left e -> error (ppTrace e)
Right res -> liftIO (putStrLn (ppPrint res))

replCommand :: String -> Repl ()
Expand Down
Loading
Loading