Newt - a dependent typed programming language

continue after import error, fix error order

+56 -18
+25 -8
src/Lib/ProcessModule.newt
··· 68 68 | Just mod => pure mod 69 69 70 70 let (False) = modns == primNS | _ => addPrimitives 71 - 71 + let freshMC = MC emptyMap Nil 0 CheckAll 72 72 let parts = split modns "." 73 73 let fn = joinBy "/" parts ++ ".newt" 74 + 75 + -- Dummy for initial load/parse 76 + let mod = MkModCtx modns "" emptyMap freshMC emptyMap Nil Nil Nil 77 + modifyTop [ currentMod := mod; hints := emptyMap; ops := emptyMap ] 78 + 74 79 -- TODO now we can pass in the module name... 75 - (fn,src) <- repo.getFile importFC fn 80 + Right (fn,src) <- tryError $ repo.getFile importFC fn 81 + | Left err => reportError err -- TODO maybe want a better FC. 82 + modifyTop [ currentMod $= [ modSource := src ]] 83 + 76 84 let (Right toks) = tokenise fn src 77 - | Left err => throwError err 85 + | Left err => reportError err 78 86 79 87 let (Right ((nameFC, modName), ops, toks)) = partialParse fn parseModHeader top.ops toks 80 - | Left (err, toks) => throwError err 88 + | Left (err, toks) => reportError err 81 89 82 90 log 1 $ \ _ => "scan imports for module \{modName}" 83 91 let (True) = modns == modName 84 - | _ => throwError $ E nameFC "module name \{show modName} doesn't match file name \{show fn}" 92 + | _ => reportError $ E nameFC "module name \{show modName} doesn't match file name \{show fn}" 85 93 86 94 let (Right (imports, ops, toks)) = partialParse fn parseImports ops toks 87 - | Left (err, toks) => throwError err 95 + | Left (err, toks) => reportError err 88 96 89 97 imported <- for imports $ \case 90 98 MkImport fc (nameFC, name') => do ··· 96 104 let imported = snoc imported primNS 97 105 98 106 putStrLn "module \{modName}" 99 - top <- getTop 107 + 108 + -- currentMod has been wiped by imports.. 100 109 let freshMC = MC emptyMap Nil 0 CheckAll 101 110 let mod = MkModCtx modns src emptyMap freshMC emptyMap imported Nil Nil 102 111 modifyTop [ currentMod := mod ··· 105 114 ] 106 115 107 116 -- top hints / ops include all directly imported modules 117 + top <- getTop 108 118 for_ imports $ \case 109 119 (MkImport fc (nameFC, ns)) => do 110 120 let (Just mod) = lookupMap' ns top.modules | _ => error emptyFC "namespace \{show ns} missing" ··· 135 145 logMetas $ reverse $ listValues top.currentMod.modMetaCtx.metas 136 146 137 147 -- print errors (for batch processing case) 138 - for_ top.currentMod.modErrors $ \ err => putStrLn $ showError src err 148 + for_ (reverse top.currentMod.modErrors) $ \ err => putStrLn $ showError src err 139 149 140 150 -- update modules with result, leave the rest of context in case this is top file 141 151 top <- getTop ··· 144 154 145 155 pure top.currentMod 146 156 where 157 + reportError : Error → M ModContext 158 + reportError err = do 159 + addError err 160 + top <- getTop 161 + modifyTop [modules $= updateMap modns top.currentMod ] 162 + pure top.currentMod 163 + 147 164 tryProcessDecl : String → String → Decl → M Unit 148 165 tryProcessDecl src ns decl = do 149 166 (Left err) <- tryError $ processDecl ns decl | _ => pure MkUnit
+8 -1
tests/BadImport.newt.fail
··· 1 1 *** Process tests/BadImport.newt 2 - ERROR at tests/BadImport.newt:4:8--4:22: error reading tests/Does/Not/Exist.newt: Error: ENOENT: no such file or directory, open 'tests/Does/Not/Exist.newt' 2 + module BadImport 3 + ERROR at tests/BadImport.newt:4:8--4:22: Error in import Does.Not.Exist 4 + 5 + -- Error should point to name here 6 + import Does.Not.Exist 7 + ^^^^^^^^^^^^^^ 8 + 9 + ERROR at tests/BadImport.newt:1:1--1:1: Compile failed
+8 -8
tests/ErrorDup.newt.fail
··· 1 1 *** Process tests/ErrorDup.newt 2 2 module ErrorDup 3 - ERROR at tests/ErrorDup.newt:9:7--9:10: Nat already declared 4 - record Nat where 3 + ERROR at tests/ErrorDup.newt:5:6--5:9: Nat already declared 4 + data Nat = Z | S Nat 5 5 6 - class Nat where 7 - ^^^ 6 + data Nat = Z | S Nat 7 + ^^^ 8 8 9 9 ERROR at tests/ErrorDup.newt:7:8--7:11: Nat already declared 10 10 data Nat = Z | S Nat ··· 12 12 record Nat where 13 13 ^^^ 14 14 15 - ERROR at tests/ErrorDup.newt:5:6--5:9: Nat already declared 16 - data Nat = Z | S Nat 15 + ERROR at tests/ErrorDup.newt:9:7--9:10: Nat already declared 16 + record Nat where 17 17 18 - data Nat = Z | S Nat 19 - ^^^ 18 + class Nat where 19 + ^^^ 20 20 21 21 ERROR at tests/ErrorDup.newt:1:1--1:1: Compile failed
+15 -1
tests/ImportError.newt.fail
··· 1 1 *** Process tests/ImportError.newt 2 - ERROR at tests/ImportError.newt:5:8--5:12: error reading tests/Blah.newt: Error: ENOENT: no such file or directory, open 'tests/Blah.newt' 2 + module Prelude 3 + module ImportError 4 + ERROR at tests/ImportError.newt:5:8--5:12: Error in import Blah 5 + -- test the FC are right and don't include next line 6 + -- TODO continue on and hit the next one. 7 + import Blah 8 + ^^^^ 9 + 10 + ERROR at tests/ImportError.newt:6:8--6:15: Error in import Foo.Bar 11 + -- TODO continue on and hit the next one. 12 + import Blah 13 + import Foo.Bar 14 + ^^^^^^^ 15 + 16 + ERROR at tests/ImportError.newt:1:1--1:1: Compile failed