Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexed language/parser types #216

Open
robrix opened this issue Sep 24, 2019 · 0 comments
Open

Indexed language/parser types #216

robrix opened this issue Sep 24, 2019 · 0 comments

Comments

@robrix
Copy link
Contributor

robrix commented Sep 24, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant