From 0b09d4d1df8158117cb4c8fdd4795b988dbfa2f4 Mon Sep 17 00:00:00 2001 From: Alan Zimmerman Date: Tue, 9 Feb 2021 14:49:07 +0000 Subject: [PATCH] Report an error if we are unable to parse the diagnostics too --- semantic-ast/src/AST/Unmarshal.hs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/semantic-ast/src/AST/Unmarshal.hs b/semantic-ast/src/AST/Unmarshal.hs index b716550943..ab2f3d3a44 100644 --- a/semantic-ast/src/AST/Unmarshal.hs +++ b/semantic-ast/src/AST/Unmarshal.hs @@ -175,6 +175,8 @@ class SymbolMatching t => Unmarshal t where where match = Match $ \ node -> do cursor <- gets cursor goto cursor (nodeTSNode node) + -- Note: checkDiagnostics could be made optional, for + -- batch usage checkDiagnostics node fmap to1 (gunmarshalNode node) @@ -182,13 +184,11 @@ class SymbolMatching t => Unmarshal t where -- ERROR or MISSING or UNEXPECTED node checkDiagnostics :: Node -> MatchM () checkDiagnostics node = do - (Loc loc _, _txt) <- unmarshalAnn @(Loc, Text.Text) node - dds <- liftIO . alloca $ (\p -> poke p (nodeTSNode node) >> ts_node_string_diagnostics_p p) + (Loc loc _) <- unmarshalAnn @Loc node + dds <- liftIO . alloca $ (\p -> poke p (nodeTSNode node) >> ts_node_string_diagnostics_p p) str <- liftIO $ peekCString dds liftIO $ free dds - let dd = if null str - then [] - else [(loc, parseDiagnostics (Text.pack str))] + let dd = [(loc, parseDiagnostics (Text.pack str)) | not (null str)] modify (\s -> s { diagnostics = diagnostics s <> UnmarshalDiagnostics dd }) @@ -485,10 +485,9 @@ parseDiagnostics str = r where r = case parseOnly posdiagnostics str of -- TODO: proper handling - Left err -> error err + Left err -> [((1,0), TSDUnexpected ("parseDiagnostics:" <> Text.pack err <> "parsing [" <> str <> "]"))] Right ds -> ds - posdiagnostics :: Attoparsec.Parser [((Int,Int), TSDiagnostic)] posdiagnostics = do xs <- many' posdiagnostic