From 54e931eabe3b6cdea0720bb201bda93e1ae3df4c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 26 Nov 2015 16:09:16 -0500 Subject: [PATCH] Handle the allocation within `parseTreeSitterFile`. --- app/Main.hs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/app/Main.hs b/app/Main.hs index 29ecfd1ba..10e9a4d82 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -70,17 +70,15 @@ parseTreeSitterFile file = do source <- newCString contents ts_document_set_input_string document source ts_document_parse document - term <- parse document contents + term <- alloca $ parse document contents ts_document_free document free source putStrLn $ "hooray" -parse :: Ptr TSDocument -> String -> IO (Term String Info) -parse document contents = do - alloca unpack where - unpack root = do - ts_document_root_node_p document root - toTerm root +parse :: Ptr TSDocument -> String -> Ptr TSNode -> IO (Term String Info) +parse document contents root = do + ts_document_root_node_p document root + toTerm root where toTerm :: Ptr TSNode -> IO (Term String Info) toTerm node = do name <- ts_node_p_name node document