Add vscode extension, command line argument, and positioned error handling.

This commit is contained in:
2024-07-04 23:40:38 -04:00
parent 0cad438f4d
commit b9f921ab3b
24 changed files with 5701 additions and 98 deletions

View File

@@ -1,6 +1,6 @@
module Main
import Control.App
-- import Control.App
import Data.String
import Data.Vect
import Data.List
@@ -23,22 +23,28 @@ import System.File
{-
- [ ] Replace on define
- [ ] more sugar on lambdas
Main2.idr has an older App attempt without the code below.
Currently working through checking of decl / def
Running check is awkward. I need a monad stack.
Main2.idr has an older App attempt without the code below. Retrofit.
App isn't compatible with javascript (without a way to short circuit
the fork foreign function.)
App was not compatible with javascript, but I have a remedy for
that now.
-}
-- TODO We're shadowing Control.App.Error do we want that?
M : Type -> Type
M = (StateT TopContext (EitherT String IO))
M = (StateT TopContext (EitherT Impl.Error IO))
dumpContext : TopContext -> M ()
dumpContext top = do
putStrLn "Context:"
go top.defs
putStrLn "---"
where
go : List TopEntry -> M ()
go [] = pure ()
go (x :: xs) = go xs >> putStrLn " \{show x}"
processDecl : Decl -> M ()
processDecl (TypeSig nm tm) = do
@@ -53,15 +59,15 @@ processDecl (Def nm raw) = do
putStrLn "def \{show nm}"
ctx <- get
let Just entry = lookup nm ctx
| Nothing => printLn "skip def \{nm} without Decl"
| Nothing => throwError $ E (0,0) "skip def \{nm} without Decl"
let (MkEntry name ty Axiom) := entry
-- FIXME error
| _ => printLn "\{nm} already defined"
| _ => throwError $ E (0,0) "\{nm} already defined"
putStrLn "check \{nm} = \{show raw} at \{show $ ty}"
let vty = eval empty ty
Right tm <- pure $ the (Either String Tm) (check ctx empty raw vty)
| Left err => printLn err
putStrLn "got \{show tm}"
let vty = eval empty CBN ty
Right tm <- pure $ the (Either Impl.Error Tm) (check ctx empty raw vty)
| Left err => throwError err
putStrLn "Ok \{show tm}"
put (addDef ctx nm tm ty)
processDecl decl = putStrLn "skip \{show decl}"
@@ -69,29 +75,31 @@ processDecl decl = putStrLn "skip \{show decl}"
processFile : String -> M ()
processFile fn = do
putStrLn "*** Process \{fn}"
Right src <- readFile $ "eg/" ++ fn
Right src <- readFile $ fn
| Left err => printLn err
let toks = tokenise src
let Right res = parse parseMod toks
| Left y => putStrLn (showError src y)
putStrLn $ pretty 80 $ pretty res
putStrLn $ render 80 $ pretty res
printLn "process Decls"
traverse_ processDecl res.decls
putStrLn "done \{show !get}"
Right _ <- tryError $ traverse_ processDecl res.decls
| Left y => putStrLn (showError src y)
dumpContext !get
main' : M ()
main' = do
args <- getArgs
putStrLn "Args: \{show args}"
Right files <- listDir "eg"
| Left err => printLn err
-- TODO use args
let (_ :: files) = args
| _ => putStrLn "Usage: newt foo.newt"
-- Right files <- listDir "eg"
-- | Left err => printLn err
traverse_ processFile (filter (".newt" `isSuffixOf`) files)
main : IO ()
main = do
foo <- runEitherT $ runStateT empty $ main'
Right _ <- runEitherT $ runStateT empty $ main'
| Left (E (c, r) str) => putStrLn "Error: \{show c} \{show r} \{show str}"
putStrLn "done"