From 2108d7287a057050f78048eb01bf1f3b23e8c983 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 10 Feb 2017 09:23:51 -0500 Subject: [PATCH] Use the new input string with length API. --- src/TreeSitter.hs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 45e0aaebf..1acc06112 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -31,15 +31,13 @@ treeSitterParser :: Language -> Ptr TS.Language -> Parser (Syntax.Syntax Text) ( treeSitterParser language grammar blob = do document <- ts_document_new ts_document_set_language document grammar - 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 + Foreign.withCStringLen (toText $ source blob) $ \ (source, len) + ts_document_set_input_string_with_length document source len + ts_document_parse document + term <- documentToTerm language document blob + ts_document_free document + pure term + -- | Return a parser for a tree sitter language & document. documentToTerm :: Language -> Ptr Document -> Parser (Syntax.Syntax Text) (Record '[Range, Category, SourceSpan])