diff --git a/src/Language.hs b/src/Language.hs index 82ac652de..285e6d658 100644 --- a/src/Language.hs +++ b/src/Language.hs @@ -50,7 +50,7 @@ termConstructor termConstructor source (range :. category :. sourceSpan :. Nil) children _ = withDefaultInfo $ case (category, children) of (Error, _) -> S.Error children - (_, []) -> S.Leaf (toText $ slice range source) + (_, []) -> S.Leaf (toText source) _ -> S.Indexed children where withDefaultInfo syntax = diff --git a/src/Language/C.hs b/src/Language/C.hs index e748dad33..2c14a54fd 100644 --- a/src/Language/C.hs +++ b/src/Language/C.hs @@ -9,7 +9,7 @@ import qualified Syntax as S import Term termConstructor - :: Source Char -- ^ The source that the term occurs within. + :: Source Char -- ^ The source of the term. -> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term. -> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term. -> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it. @@ -17,7 +17,7 @@ termConstructor termConstructor source (range :. category :. sourceSpan :. Nil) children _ | category == Error = withDefaultInfo (S.Error children) | otherwise = withDefaultInfo $ case children of - [] -> S.Leaf . toText $ slice range source + [] -> S.Leaf $ toText source _ -> S.Indexed children where withDefaultInfo syntax = pure $! cofree ((range :. category :. sourceSpan :. Nil) :< syntax) diff --git a/src/Language/Go.hs b/src/Language/Go.hs index 17a1d4b05..31a2d4018 100644 --- a/src/Language/Go.hs +++ b/src/Language/Go.hs @@ -11,7 +11,7 @@ import Range (unionRangesFrom) import SourceSpan (unionSourceSpansFrom) termConstructor - :: Source Char -- ^ The source that the term occurs within. + :: Source Char -- ^ The source of the term. -> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term. -> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term. -> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it. @@ -103,17 +103,17 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children _ = pur let params = withRanges range Params children $ S.Indexed children in withDefaultInfo $ S.Ty params IncrementStatement -> - withDefaultInfo $ S.Leaf . toText $ slice range source + withDefaultInfo $ S.Leaf $ toText source DecrementStatement -> - withDefaultInfo $ S.Leaf . toText $ slice range source + withDefaultInfo $ S.Leaf $ toText source QualifiedIdentifier -> - withDefaultInfo $ S.Leaf . toText $ slice range source + withDefaultInfo $ S.Leaf $ toText source Break -> toBreak children Continue -> toContinue children Pair -> toPair children Method -> toMethod children _ -> withDefaultInfo $ case children of - [] -> S.Leaf . toText $ slice range source + [] -> S.Leaf $ toText source _ -> S.Indexed children where toMethod = \case diff --git a/src/Language/JavaScript.hs b/src/Language/JavaScript.hs index 6c42ad279..247025db4 100644 --- a/src/Language/JavaScript.hs +++ b/src/Language/JavaScript.hs @@ -13,7 +13,7 @@ operators :: [Category] operators = [ Operator, BooleanOperator, MathOperator, RelationalOperator, BitwiseOperator ] termConstructor - :: Source Char -- ^ The source that the term occurs within. + :: Source Char -- ^ The source of the term. -> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term. -> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term. -> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it. @@ -54,7 +54,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil (Case, _ ) -> S.Error children (Object, _) -> S.Object Nothing $ foldMap toTuple children (Pair, _) -> S.Fixed children - (Comment, _) -> S.Comment . toText $ slice range source + (Comment, _) -> S.Comment $ toText source (If, expr : rest ) -> S.If expr rest (If, _ ) -> S.Error children (While, expr : rest ) -> S.While expr rest @@ -98,7 +98,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil [ params, body ] -> S.AnonymousFunction (toList (unwrap params)) [body] [ id, params, body ] -> S.Function id (toList (unwrap params)) [body] _ -> S.Error children - (_, []) -> S.Leaf . toText $ slice range source + (_, []) -> S.Leaf $ toText source _ -> S.Indexed children where withDefaultInfo syntax = diff --git a/src/Language/Ruby.hs b/src/Language/Ruby.hs index af344fa8d..405cb3874 100644 --- a/src/Language/Ruby.hs +++ b/src/Language/Ruby.hs @@ -14,7 +14,7 @@ operators :: [Category] operators = [ Binary, Unary, RangeExpression, ScopeOperator ] termConstructor - :: Source Char -- ^ The source that the term occurs within. + :: Source Char -- ^ The source of the term. -> Record '[Range, Category, SourceSpan] -- ^ The proposed annotation for the term. -> [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ The child nodes of the term. -> IO [ SyntaxTerm Text '[Range, Category, SourceSpan] ] -- ^ All child nodes (included unnamed productions) of the term as 'IO'. Only use this if you need it. @@ -58,7 +58,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil (Class, _ ) -> S.Error children (SingletonClass, identifier : rest ) -> S.Class identifier Nothing rest (SingletonClass, _ ) -> S.Error children - (Comment, _ ) -> S.Comment . toText $ slice range source + (Comment, _ ) -> S.Comment $ toText source (Ternary, condition : cases) -> S.Ternary condition cases (Ternary, _ ) -> S.Error children (Constant, _ ) -> S.Fixed children @@ -117,7 +117,7 @@ termConstructor source (range :. category :. sourceSpan :. Nil) children allChil (While, _ ) -> S.Error children (Yield, _ ) -> S.Yield children _ | category `elem` [ BeginBlock, EndBlock ] -> S.BlockStatement children - (_, []) -> S.Leaf . toText $ slice range source + (_, []) -> S.Leaf $ toText source _ -> S.Indexed children where withRecord record syntax = cofree (record :< syntax) diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index d2a11ce0d..d6db15a71 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -57,7 +57,7 @@ documentToTerm language document SourceBlob{..} = alloca $ \ root -> do -- Without it, we may not evaluate the value 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` sourceSpan `seq` assignTerm language source (range :. categoryForLanguageProductionName language (toS name) :. sourceSpan :. Nil) children allChildren + range `seq` sourceSpan `seq` assignTerm language (slice range source) (range :. categoryForLanguageProductionName language (toS name) :. sourceSpan :. Nil) children allChildren getChild node n out = ts_node_p_named_child node n out >> toTerm out {-# INLINE getChild #-} getUnnamedChild node n out = ts_node_p_child node n out >> toTerm out