1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Define a helper extracting all errors from a Term.

This commit is contained in:
Rob Rix 2017-06-06 09:40:57 -04:00
parent a88e675239
commit 5a37e17a6c

View File

@ -70,6 +70,11 @@ runParser parser = case parser of
MarkdownParser -> cmarkParser
LineByLineParser -> lineByLineParser
termErrors :: (InUnion fs (Syntax.Error (Error grammar)), Functor (Union fs)) => Term (Union fs) a -> [Error grammar]
termErrors = cata $ \ (_ :< s) -> case s of
_ | Just (Syntax.Error err) <- prj s -> [err]
_ -> []
-- | A fallback parser that treats a file simply as rows of strings.
lineByLineParser :: Source -> IO (SyntaxTerm Text DefaultFields)
lineByLineParser source = pure . cofree . root $ case foldl' annotateLeaves ([], 0) lines of