diff --git a/src/Parser.hs b/src/Parser.hs index 33f8d1181..60ad3fa93 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -30,8 +30,7 @@ import qualified Language.Python.Syntax as Python import qualified Language.Ruby.Syntax as Ruby import Syntax hiding (Go) import Term -import qualified TreeSitter as TS -import TreeSitter.Language (Symbol) +import qualified TreeSitter.Language as TS (Language, Symbol) import TreeSitter.Go import TreeSitter.Python import TreeSitter.Ruby @@ -43,7 +42,7 @@ data Parser term where -- | A parser producing 'AST' using a 'TS.Language'. ASTParser :: (Bounded grammar, Enum grammar) => Ptr TS.Language -> Parser (AST grammar) -- | A parser producing an à la carte term given an 'AST'-producing parser and an 'Assignment' onto 'Term's in some syntax type. - AssignmentParser :: (Bounded grammar, Ix grammar, Show grammar, Symbol grammar, Syntax.Error :< fs, Apply1 Foldable fs, Apply1 Functor fs, Eq ast, Recursive ast, Foldable (Base ast)) + AssignmentParser :: (Bounded grammar, Ix grammar, Show grammar, TS.Symbol grammar, Syntax.Error :< fs, Apply1 Foldable fs, Apply1 Functor fs, Eq ast, Recursive ast, Foldable (Base ast)) => Parser ast -- ^ A parser producing AST. -> (forall x. Base ast x -> Node grammar) -- ^ A function extracting the symbol and location. -> Assignment ast grammar (Term (Union fs) (Record Location)) -- ^ An assignment from AST onto 'Term's. diff --git a/src/TreeSitter.hs b/src/TreeSitter.hs index 5a470caa0..c9b325a3a 100644 --- a/src/TreeSitter.hs +++ b/src/TreeSitter.hs @@ -59,7 +59,7 @@ parseToAST language Blob{..} = bracket TS.ts_document_new TS.ts_document_free $ anaM toAST root -toAST :: forall grammar . (Bounded grammar, Enum grammar) => Node -> IO (Base (A.AST grammar) Node) +toAST :: forall grammar . (Bounded grammar, Enum grammar) => TS.Node -> IO (Base (A.AST grammar) TS.Node) toAST node@TS.Node{..} = do let count = fromIntegral nodeChildCount children <- allocaArray count $ \ childNodesPtr -> do @@ -72,13 +72,13 @@ anaM g = a where a = pure . embed <=< traverse a <=< g -- | Return a parser for a tree sitter language & document. -documentToTerm :: Ptr TS.Language -> Ptr Document -> Blob -> IO (SyntaxTerm DefaultFields) +documentToTerm :: Ptr TS.Language -> Ptr TS.Document -> Blob -> IO (SyntaxTerm DefaultFields) documentToTerm language document Blob{..} = do root <- alloca (\ rootPtr -> do TS.ts_document_root_node_p document rootPtr peek rootPtr) toTerm root - where toTerm :: Node -> IO (SyntaxTerm DefaultFields) + where toTerm :: TS.Node -> IO (SyntaxTerm DefaultFields) toTerm node@TS.Node{..} = do name <- peekCString nodeType