From a4cfd49e5cd98e7838668f852075fee09780833c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 6 Jun 2017 09:41:41 -0400 Subject: [PATCH] Show all errors in assigned terms. --- src/Parser.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Parser.hs b/src/Parser.hs index 963767442..c11c41440 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -30,7 +30,7 @@ data Parser term where -- | A parser producing 'AST' using a 'TS.Language'. ASTParser :: (Bounded grammar, Enum grammar) => Ptr TS.Language -> Parser (AST grammar) -- | A parser producing an à la carte term given an 'AST'-producing parser and an 'Assignment' onto 'Term's in some syntax type. Assignment errors will result in a top-level 'Syntax.Error' node. - AssignmentParser :: (Bounded grammar, Enum grammar, Eq grammar, Show grammar, Symbol grammar, InUnion fs (Syntax.Error (Error grammar))) + AssignmentParser :: (Bounded grammar, Enum grammar, Eq grammar, Show grammar, Symbol grammar, InUnion fs (Syntax.Error (Error grammar)), Functor (Union fs)) => Parser (AST grammar) -- ^ A parser producing 'AST'. -> Assignment (Node grammar) (Term (Union fs) Location) -- ^ An assignment from 'AST' onto 'Term's. -> Parser (Term (Union fs) Location) -- ^ A parser of 'Term's. @@ -65,7 +65,11 @@ runParser parser = case parser of ast <- runParser parser source let Result err term = assign assignment source ast traverse_ (putStr . ($ "") . showError source) err - pure (fromMaybe (cofree ((totalRange source :. totalSpan source :. Nil) :< inj (Syntax.Error (fromMaybe (Error (SourcePos 0 0) (UnexpectedEndOfInput [])) err)))) term) + case term of + Just term -> do + traverse_ (putStr . ($ "") . showError source) (termErrors term `asTypeOf` toList err) + pure term + Nothing -> pure $! cofree ((totalRange source :. totalSpan source :. Nil) :< inj (Syntax.Error (fromMaybe (Error (SourcePos 0 0) (UnexpectedEndOfInput [])) err))) TreeSitterParser language tslanguage -> treeSitterParser language tslanguage MarkdownParser -> cmarkParser LineByLineParser -> lineByLineParser