1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Use the new input string with length API.

This commit is contained in:
Rob Rix 2017-02-10 09:23:51 -05:00
parent c7366062b4
commit 2108d7287a

View File

@ -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])