From e2a629121e45df41bb4ad295c1fd4d424188f311 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 14 Jul 2017 14:42:26 -0400 Subject: [PATCH 1/2] Bump haskell-tree-sitter for ParseError as the maximal constructor. --- vendor/haskell-tree-sitter | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 17c44abac..5607136d2 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 17c44abac3f72acc26615cb3299d2924671326c7 +Subproject commit 5607136d25485b82159412948e7933f548381a12 From b66cfcc52c5392f31623b66f4ee8aa74bd728fc9 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 14 Jul 2017 14:43:36 -0400 Subject: [PATCH 2/2] Select the lesser of the node symbol & the parse error symbol. This effectively clamps the ERROR symbol (65535) to the maximal constructor. --- src/TreeSitter.hs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index bca8f2477..16106a0a7 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -53,13 +53,13 @@ parseToAST language source = bracket ts_document_new ts_document_free $ \ docume anaM toAST root -toAST :: (Bounded grammar, Enum grammar) => Node -> IO (Base (A.AST grammar) Node) +toAST :: forall grammar . (Bounded grammar, Enum grammar) => Node -> IO (Base (A.AST grammar) Node) toAST node@Node{..} = do let count = fromIntegral nodeChildCount children <- allocaArray count $ \ childNodesPtr -> do _ <- with nodeTSNode (\ nodePtr -> ts_node_copy_child_nodes nullPtr nodePtr childNodesPtr (fromIntegral count)) peekArray count childNodesPtr - pure $! A.Node (toEnum (fromIntegral nodeSymbol)) (nodeRange node) (nodeSpan node) :< children + pure $! A.Node (toEnum (min (fromIntegral nodeSymbol) (fromEnum (maxBound :: grammar)))) (nodeRange node) (nodeSpan node) :< children anaM :: (Corecursive t, Monad m, Traversable (Base t)) => (a -> m (Base t a)) -> a -> m t anaM g = a where a = pure . embed <=< traverse a <=< g