From d6796afd6f719209c5fc285543a4f1c61c4a9d7f Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Thu, 9 Feb 2017 21:31:29 -0800 Subject: [PATCH] Pass Text to tree-sitter --- src/TreeSitter.hs | 18 +++++++++++------- vendor/haskell-tree-sitter | 2 +- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 378e6b56c..45e0aaebf 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -17,7 +17,8 @@ import Range import Source import qualified Syntax import Foreign -import Foreign.C.String +import Foreign.C.String as FString (peekCString, withCStringLen) +import Data.Text.Foreign as Foreign import qualified Syntax as S import Term import Text.Parser.TreeSitter hiding (Language(..)) @@ -30,12 +31,15 @@ treeSitterParser :: Language -> Ptr TS.Language -> Parser (Syntax.Syntax Text) ( treeSitterParser language grammar blob = do document <- ts_document_new ts_document_set_language document grammar - withCString (toString $ source blob) (\source -> do - ts_document_set_input_string document source - ts_document_parse document - term <- documentToTerm language document blob - ts_document_free document - pure term) + let termWithCString (source, len) = do + ts_document_set_input_string2 document source len + ts_document_parse document + term <- documentToTerm language document blob + ts_document_free document + pure term + if Source.null (source blob) + then FString.withCStringLen "" termWithCString + else Foreign.withCStringLen (toText $ source blob) termWithCString -- | Return a parser for a tree sitter language & document. documentToTerm :: Language -> Ptr Document -> Parser (Syntax.Syntax Text) (Record '[Range, Category, SourceSpan]) diff --git a/vendor/haskell-tree-sitter b/vendor/haskell-tree-sitter index 8116ff5ec..cec2607f9 160000 --- a/vendor/haskell-tree-sitter +++ b/vendor/haskell-tree-sitter @@ -1 +1 @@ -Subproject commit 8116ff5ec37cae106ed78771a9676057ad702b80 +Subproject commit cec2607f906245315e0fcea8be9754c563846860