From 8de29e22271ea8d3c6fcc0601053032cb9937ff4 Mon Sep 17 00:00:00 2001 From: krasimir Date: Wed, 9 Dec 2009 22:43:17 +0000 Subject: [PATCH] function read_file now reports errors if there is expression with parse or type error --- src/GF/Command/Commands.hs | 18 +++++++++++++++--- 1 file 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")]