From 9750b252ed3c8a0f4b817690955e70c212169166 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 7 Sep 2016 11:57:24 -0400 Subject: [PATCH] Rename the term constructor for JS. --- src/Language/JavaScript.hs | 4 ++-- src/TreeSitter.hs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Language/JavaScript.hs b/src/Language/JavaScript.hs index 1cee70ee7..3ebad237f 100644 --- a/src/Language/JavaScript.hs +++ b/src/Language/JavaScript.hs @@ -9,14 +9,14 @@ import SourceSpan import qualified Syntax as S import Term -javascriptTermConstructor +termConstructor :: Source Char -- ^ The source that the term occurs within. -> IO SourceSpan -- ^ The span that the term occupies. This is passed in 'IO' to guarantee some access constraints & encourage its use only when needed (improving performance). -> Text -- ^ The name of the production for this node. -> Range -- ^ The character range that the term occupies. -> [Term Text (Record '[Range, Category])] -- ^ The child nodes of the term. -> IO (Term Text (Record '[Range, Category])) -- ^ The resulting term, in IO. -javascriptTermConstructor source sourceSpan name range children +termConstructor source sourceSpan name range children | name == "ERROR" = sourceSpan >>= withDefaultInfo . (`S.Error` children) | otherwise = withDefaultInfo $ case (name, children) of ("return_statement", _) -> S.Return (listToMaybe children) diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 031190f41..6d5500515 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -6,7 +6,7 @@ import Control.Monad import Category import Data.Record import Language -import Language.JavaScript +import qualified Language.JavaScript as JS import Parser import Range import Source @@ -48,6 +48,6 @@ documentToTerm language document blob = alloca $ \ root -> do , spanEnd = SourcePos (fromIntegral $! ts_node_p_end_point_row node) (fromIntegral $! ts_node_p_end_point_column node) } -- Note: The strict application here is semantically important. Without it, we may not evaluate the range until after we’ve exited the scope that `node` was allocated within, meaning `alloca` will free it & other stack data may overwrite it. - range `seq` javascriptTermConstructor (source blob) (sourceSpan `seq` pure sourceSpan) (toS name) range (filter (\child -> category (extract child) /= Empty) children) + range `seq` JS.termConstructor (source blob) (sourceSpan `seq` pure sourceSpan) (toS name) range (filter (\child -> category (extract child) /= Empty) children) getChild node n out = ts_node_p_named_child node n out >> toTerm out {-# INLINE getChild #-}