Open
Description
It occurred to me that Language
, Parser
, etc. could have a (phantom) type parameter for the AST they relate to:
-- in TreeSitter.Language
data Language a
-- in the internal module
foreign import ccall unsafe "vendor/tree-sitter-python/src/parser.c tree_sitter_python" tree_sitter_python :: Ptr (Language a)
-- in the public module
import qualified TreeSitter.Python.AST as AST
import qualified TreeSitter.Python.Internal as Internal
python :: Ptr (Language (AST.Module a))
python = Internal.tree_sitter_python
-- in TreeSitter.Unmarshal
parseByteString :: Unmarshal t => Ptr (TS.Language t) -> ByteString -> IO (Either String t)
This would be a pretty big usability improvement for parseByteString
, which otherwise can’t generally infer the type of t
.
We might want to index it by the grammar type as well:
python :: Ptr (Language Grammar (AST.Module a))
python = Internal.tree_sitter_python
as that would then allow us to index Tree
& Node
by the Grammar
type, making it much easier to work with their symbols.