diff options
| author | krasimir <krasimir@chalmers.se> | 2009-12-09 22:43:17 +0000 |
|---|---|---|
| committer | krasimir <krasimir@chalmers.se> | 2009-12-09 22:43:17 +0000 |
| commit | fae0ade0203e42d3b8d86b3ed20b78657b0c2506 (patch) | |
| tree | 96ac86247e9272f8d95a0da979c7b7ef40543fc2 /src/GF/Command/Commands.hs | |
| parent | c8ceed08efcc0bdc1fcbd89bce643d9f52f0991b (diff) | |
function read_file now reports errors if there is expression with parse or type error
Diffstat (limited to 'src/GF/Command/Commands.hs')
| -rw-r--r-- | src/GF/Command/Commands.hs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/GF/Command/Commands.hs b/src/GF/Command/Commands.hs index 73730b050..a54067dd6 100644 --- a/src/GF/Command/Commands.hs +++ b/src/GF/Command/Commands.hs @@ -505,12 +505,24 @@ allCommands cod env@(pgf, mos) = Map.fromList [ ], exec = \opts _ -> do let file = valStrOpts "file" "_gftmp" opts + let exprs [] = ([],empty) + exprs ((n,s):ls) = case readExpr s of + Just e -> let (es,err) = exprs ls + in case inferExpr pgf e of + Right (e,t) -> (e:es,err) + Left tcerr -> (es,text "on line" <+> int n <> colon $$ nest 2 (ppTcError tcerr) $$ err) + Nothing -> let (es,err) = exprs ls + in (es,text "on line" <+> int n <> colon <+> text "parse error" $$ err) + returnFromLines ls = case exprs ls of + (es, err) | null es -> return ([], render (err $$ text "no trees found")) + | otherwise -> return (es, render err) + s <- readFile file case opts of _ | isOpt "lines" opts && isOpt "tree" opts -> - returnFromExprs [e | l <- lines s, Just e0 <- [readExpr l], Right (e,t) <- [inferExpr pgf e0]] - _ | isOpt "tree" opts -> - returnFromExprs [e | Just e0 <- [readExpr s], Right (e,t) <- [inferExpr pgf e0]] + returnFromLines (zip [1..] (lines s)) + _ | isOpt "tree" opts -> + returnFromLines [(1,s)] _ | isOpt "lines" opts -> return (fromStrings $ lines s) _ -> return (fromString s), flags = [("file","the input file name")] |
