forked from GitHub/gf-core
report type errors in the shell from command "p"
This commit is contained in:
@@ -482,7 +482,7 @@ allCommands env@(pgf, mos) = Map.fromList [
|
|||||||
"will accept unknown adjectives, nouns and verbs with the resource grammar."
|
"will accept unknown adjectives, nouns and verbs with the resource grammar."
|
||||||
],
|
],
|
||||||
exec = \opts ts ->
|
exec = \opts ts ->
|
||||||
return $ fromParse opts ts $ concatMap (par opts) $ toStrings ts,
|
return $ fromParse opts (concat [map ((,) s) (par opts s) | s <- toStrings ts]),
|
||||||
flags = [
|
flags = [
|
||||||
("cat","target category of parsing"),
|
("cat","target category of parsing"),
|
||||||
("lang","the languages of parsing (comma-separated, no spaces)"),
|
("lang","the languages of parsing (comma-separated, no spaces)"),
|
||||||
@@ -1003,16 +1003,20 @@ allCommands env@(pgf, mos) = Map.fromList [
|
|||||||
toStrings = map showAsString
|
toStrings = map showAsString
|
||||||
toString = unwords . toStrings
|
toString = unwords . toStrings
|
||||||
|
|
||||||
fromParse opts ts parses
|
fromParse opts [] = ([],"")
|
||||||
| isOpt "bracket" opts = ([], unlines $ map showBracketedString bss)
|
fromParse opts ((s,(po,bs)):ps)
|
||||||
| otherwise = case ts of
|
| isOpt "bracket" opts = (es, showBracketedString bs
|
||||||
[] -> ([], "no trees found" ++
|
++ "\n" ++ msg)
|
||||||
missingWordMsg (optMorpho opts) (concatMap words (toStrings ts))
|
| otherwise = case po of
|
||||||
)
|
ParseOk ts -> let (es',msg') = fromExprs ts
|
||||||
_ -> fromExprs ts
|
in (es'++es,msg'++msg)
|
||||||
|
TypeError errs -> ([], render (text "The parsing is successful but the type checking failed with error(s):" $$
|
||||||
|
nest 2 (vcat (map (ppTcError . snd) errs)))
|
||||||
|
++ "\n" ++ msg)
|
||||||
|
ParseFailed i -> ([], "parse failed at token " ++ show (words s !! max 0 (i-1))
|
||||||
|
++ "\n" ++ msg)
|
||||||
where
|
where
|
||||||
(prs,bss) = unzip parses
|
(es,msg) = fromParse opts ps
|
||||||
ts = [t | ParseOk ts <- prs, t <- ts]
|
|
||||||
|
|
||||||
returnFromExprs es = return $ case es of
|
returnFromExprs es = return $ case es of
|
||||||
[] -> ([], "no trees found")
|
[] -> ([], "no trees found")
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ convertFile conf src file = do
|
|||||||
[] -> return ()
|
[] -> return ()
|
||||||
_ -> appv (" missing words: " ++ unwords ws)
|
_ -> appv (" missing words: " ++ unwords ws)
|
||||||
return ws
|
return ws
|
||||||
TypeError _ _ ->
|
TypeError _ ->
|
||||||
return []
|
return []
|
||||||
ParseOk ts ->
|
ParseOk ts ->
|
||||||
case rank ts of
|
case rank ts of
|
||||||
|
|||||||
@@ -44,11 +44,12 @@ data ParseInput
|
|||||||
-- | This data type encodes the different outcomes which you could get from the parser.
|
-- | This data type encodes the different outcomes which you could get from the parser.
|
||||||
data ParseOutput
|
data ParseOutput
|
||||||
= ParseFailed Int -- ^ The integer is the position in number of tokens where the parser failed.
|
= ParseFailed Int -- ^ The integer is the position in number of tokens where the parser failed.
|
||||||
| TypeError FId [TcError] -- ^ The parsing was successful but none of the trees is type correct.
|
| TypeError [(FId,TcError)] -- ^ The parsing was successful but none of the trees is type correct.
|
||||||
-- The forest id ('FId') points to the bracketed string from the parser
|
-- The forest id ('FId') points to the bracketed string from the parser
|
||||||
-- where the type checking failed. More than one error is returned
|
-- where the type checking failed. More than one error is returned
|
||||||
-- if there are many analizes for some phrase but they all are not type correct.
|
-- if there are many analizes for some phrase but they all are not type correct.
|
||||||
| ParseOk [Tree] -- ^ If the parsing was successful we get a list of abstract syntax trees. The list should be non-empty.
|
| ParseOk [Tree] -- ^ If the parsing and the type checkeing are successful we get a list of abstract syntax trees.
|
||||||
|
-- The list should be non-empty.
|
||||||
|
|
||||||
parse :: PGF -> Language -> Type -> [Token] -> (ParseOutput,BracketedString)
|
parse :: PGF -> Language -> Type -> [Token] -> (ParseOutput,BracketedString)
|
||||||
parse pgf lang typ toks = loop (initState pgf lang typ) toks
|
parse pgf lang typ toks = loop (initState pgf lang typ) toks
|
||||||
|
|||||||
Reference in New Issue
Block a user