diff options
| author | Thomas Vigouroux <tomvig38@gmail.com> | 2020-04-19 09:45:54 +0200 |
|---|---|---|
| committer | Thomas Vigouroux <tomvig38@gmail.com> | 2020-04-19 09:45:54 +0200 |
| commit | 2526baf4cc5ea540188345c856adb162ce102674 (patch) | |
| tree | 6bdf2bb238354161c484e92e575a30a7d77b7d09 /lua/nvim-treesitter/parsers.lua | |
| parent | 5897d72b075991e4de5876c918be186d4551cf12 (diff) | |
feat: add parsers module and better match iter
The `parsers` module manages parsers for us, for now only in a really
basic way.
iter_prepared_mathes iters on an enhanced versions of the matches, where
captures are directly accessible via their names to allow things like :
((itentifier) @def.first (identifier) @def.last)
To be handled like this in lua:
match.def.first
match.def.last
Also adds a `set!` predicate to allow setting data within the prepared
match (see queries/lua/locals.scm) for examples.
Diffstat (limited to 'lua/nvim-treesitter/parsers.lua')
| -rw-r--r-- | lua/nvim-treesitter/parsers.lua | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua new file mode 100644 index 00000000..c8517773 --- /dev/null +++ b/lua/nvim-treesitter/parsers.lua @@ -0,0 +1,21 @@ +local api = vim.api +local ts = vim.treesitter + +local M = {} + +function M.has_parser(lang) + local lang = lang or api.nvim_buf_get_option(0, 'filetype') + return #api.nvim_get_runtime_file('parser/' .. lang .. '.*', false) > 0 +end + +function M.get_parser(bufnr) + if M.has_parser() then + local buf = bufnr or api.nvim_get_current_buf() + if not M[buf] then + M[buf] = ts.get_parser(buf) + end + return M[buf] + end +end + +return M |
