feat(ts): add mustache parser with cloudinit filetype alias
This commit is contained in:
@@ -92,3 +92,30 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
This software includes tree-sitter queries derived from tree-sitter-mustache
|
||||||
|
(https://github.com/TheLeoP/tree-sitter-mustache)
|
||||||
|
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2024-2025 TheLeoP
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|||||||
@@ -63,6 +63,12 @@ require("ts").setup({
|
|||||||
"https://github.com/tree-sitter/tree-sitter-html",
|
"https://github.com/tree-sitter/tree-sitter-html",
|
||||||
"https://github.com/tree-sitter/tree-sitter-json",
|
"https://github.com/tree-sitter/tree-sitter-json",
|
||||||
"https://github.com/tree-sitter-grammars/tree-sitter-luadoc",
|
"https://github.com/tree-sitter-grammars/tree-sitter-luadoc",
|
||||||
|
{
|
||||||
|
src = "https://github.com/TheLeoP/tree-sitter-mustache",
|
||||||
|
aliases = {
|
||||||
|
{ lang = "cloudinit", filetypes = { "cloudinit" } },
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
src = "https://github.com/tree-sitter/tree-sitter-php",
|
src = "https://github.com/tree-sitter/tree-sitter-php",
|
||||||
parsers = {
|
parsers = {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
vim.filetype.add({
|
vim.filetype.add({
|
||||||
pattern = {
|
pattern = {
|
||||||
[".*%.xml%.tmpl"] = "gotmpl",
|
[".*%.xml%.tmpl"] = "gotmpl",
|
||||||
|
[".*%.cloud%-init%.yml"] = "cloudinit",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
+54
-10
@@ -2,12 +2,17 @@ local log = require("log")
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
---@class ow.TS.Alias
|
||||||
|
---@field lang string
|
||||||
|
---@field filetypes? string[]
|
||||||
|
|
||||||
---@class ow.TS.Parser
|
---@class ow.TS.Parser
|
||||||
---@field lang string
|
---@field lang string
|
||||||
---@field location? string
|
---@field location? string
|
||||||
---@field generate? boolean
|
---@field generate? boolean
|
||||||
---@field from_json? boolean
|
---@field from_json? boolean
|
||||||
---@field filetypes? string[]
|
---@field filetypes? string[]
|
||||||
|
---@field aliases? ow.TS.Alias[]
|
||||||
|
|
||||||
---@class ow.TS.RepoBase
|
---@class ow.TS.RepoBase
|
||||||
---@field src string
|
---@field src string
|
||||||
@@ -24,6 +29,7 @@ local M = {}
|
|||||||
---@field generate? boolean
|
---@field generate? boolean
|
||||||
---@field from_json? boolean
|
---@field from_json? boolean
|
||||||
---@field filetypes? string[]
|
---@field filetypes? string[]
|
||||||
|
---@field aliases? ow.TS.Alias[]
|
||||||
|
|
||||||
---@class ow.TS.MultiSpec : ow.TS.RepoBase
|
---@class ow.TS.MultiSpec : ow.TS.RepoBase
|
||||||
---@field parsers ow.TS.Parser[]
|
---@field parsers ow.TS.Parser[]
|
||||||
@@ -52,28 +58,62 @@ local function start_treesitter(buf)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param parser ow.TS.Parser
|
---@param lang string
|
||||||
---@param so string
|
---@param so string
|
||||||
local function register(parser, so)
|
---@param filetypes? string[]
|
||||||
vim.treesitter.language.add(parser.lang, { path = so })
|
---@param symbol_name? string
|
||||||
local filetypes = { parser.lang }
|
local function register_lang(lang, so, filetypes, symbol_name)
|
||||||
if parser.filetypes then
|
vim.treesitter.language.add(
|
||||||
vim.treesitter.language.register(parser.lang, parser.filetypes)
|
lang,
|
||||||
vim.list_extend(filetypes, parser.filetypes)
|
{ path = so, symbol_name = symbol_name }
|
||||||
|
)
|
||||||
|
local fts = { lang }
|
||||||
|
if filetypes then
|
||||||
|
vim.treesitter.language.register(lang, filetypes)
|
||||||
|
vim.list_extend(fts, filetypes)
|
||||||
end
|
end
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
group = vim.api.nvim_create_augroup(
|
group = vim.api.nvim_create_augroup(
|
||||||
"ow.ts.parser." .. parser.lang,
|
"ow.ts.parser." .. lang,
|
||||||
{ clear = true }
|
{ clear = true }
|
||||||
),
|
),
|
||||||
pattern = filetypes,
|
pattern = fts,
|
||||||
callback = function(ev)
|
callback = function(ev)
|
||||||
start_treesitter(ev.buf)
|
start_treesitter(ev.buf)
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---@class ow.TS.LangEntry
|
||||||
|
---@field lang string
|
||||||
|
---@field filetypes? string[]
|
||||||
|
---@field symbol_name? string
|
||||||
|
|
||||||
|
---@param parser ow.TS.Parser
|
||||||
|
---@return ow.TS.LangEntry[]
|
||||||
|
local function parser_langs(parser)
|
||||||
|
local entries = {
|
||||||
|
{ lang = parser.lang, filetypes = parser.filetypes },
|
||||||
|
}
|
||||||
|
for _, alias in ipairs(parser.aliases or {}) do
|
||||||
|
table.insert(entries, {
|
||||||
|
lang = alias.lang,
|
||||||
|
filetypes = alias.filetypes,
|
||||||
|
symbol_name = parser.lang,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
return entries
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param parser ow.TS.Parser
|
||||||
|
---@param so string
|
||||||
|
local function register(parser, so)
|
||||||
|
for _, e in ipairs(parser_langs(parser)) do
|
||||||
|
register_lang(e.lang, so, e.filetypes, e.symbol_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
---@param lang string
|
---@param lang string
|
||||||
local function activate_open_buffers(lang)
|
local function activate_open_buffers(lang)
|
||||||
local fts = vim.treesitter.language.get_filetypes(lang)
|
local fts = vim.treesitter.language.get_filetypes(lang)
|
||||||
@@ -110,7 +150,9 @@ local function build(repo, parser)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
register(parser, out)
|
register(parser, out)
|
||||||
activate_open_buffers(parser.lang)
|
for _, e in ipairs(parser_langs(parser)) do
|
||||||
|
activate_open_buffers(e.lang)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function do_build()
|
local function do_build()
|
||||||
@@ -206,6 +248,7 @@ local function spec_to_repo(spec)
|
|||||||
generate = pick(s.generate, spec.generate),
|
generate = pick(s.generate, spec.generate),
|
||||||
from_json = pick(s.from_json, spec.from_json),
|
from_json = pick(s.from_json, spec.from_json),
|
||||||
filetypes = s.filetypes,
|
filetypes = s.filetypes,
|
||||||
|
aliases = s.aliases,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
@@ -225,6 +268,7 @@ local function spec_to_repo(spec)
|
|||||||
generate = spec.generate,
|
generate = spec.generate,
|
||||||
from_json = spec.from_json,
|
from_json = spec.from_json,
|
||||||
filetypes = spec.filetypes,
|
filetypes = spec.filetypes,
|
||||||
|
aliases = spec.aliases,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -101,6 +101,10 @@
|
|||||||
"rev": "873612aadd3f684dd4e631bdf42ea8990c57634e",
|
"rev": "873612aadd3f684dd4e631bdf42ea8990c57634e",
|
||||||
"src": "https://github.com/tree-sitter-grammars/tree-sitter-luadoc"
|
"src": "https://github.com/tree-sitter-grammars/tree-sitter-luadoc"
|
||||||
},
|
},
|
||||||
|
"tree-sitter-mustache": {
|
||||||
|
"rev": "0f1f3cf07508a64b84cbff457f1446a787c48a0e",
|
||||||
|
"src": "https://github.com/TheLeoP/tree-sitter-mustache"
|
||||||
|
},
|
||||||
"tree-sitter-php": {
|
"tree-sitter-php": {
|
||||||
"rev": "3f2465c217d0a966d41e584b42d75522f2a3149e",
|
"rev": "3f2465c217d0a966d41e584b42d75522f2a3149e",
|
||||||
"src": "https://github.com/tree-sitter/tree-sitter-php"
|
"src": "https://github.com/tree-sitter/tree-sitter-php"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
; inherits: mustache
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
; inherits: mustache
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
; inherits: mustache
|
||||||
|
|
||||||
|
((text) @injection.content
|
||||||
|
(#set! injection.language "yaml")
|
||||||
|
(#set! injection.combined))
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
[
|
||||||
|
(inverted_section)
|
||||||
|
(section)
|
||||||
|
] @fold
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
; Forked from https://github.com/TheLeoP/tree-sitter-mustache
|
||||||
|
; Copyright (c) 2024-2025 TheLeoP
|
||||||
|
; Licensed under the MIT license.
|
||||||
|
; Modifications Copyright 2026 Oscar Wallberg, Apache-2.0
|
||||||
|
|
||||||
|
[
|
||||||
|
(start_delimiter)
|
||||||
|
(end_delimiter)
|
||||||
|
"{"
|
||||||
|
"}"
|
||||||
|
] @punctuation.bracket
|
||||||
|
|
||||||
|
(identifier) @variable
|
||||||
|
|
||||||
|
(partial_content) @module
|
||||||
|
|
||||||
|
"." @punctuation.delimiter
|
||||||
|
|
||||||
|
[
|
||||||
|
"#"
|
||||||
|
"/"
|
||||||
|
"^"
|
||||||
|
">"
|
||||||
|
] @punctuation.special
|
||||||
|
|
||||||
|
(comment_statement) @comment @spell
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
((comment_statement) @injection.content
|
||||||
|
(#set! injection.language "comment"))
|
||||||
Reference in New Issue
Block a user