feat(wxml): add parser and queries

This commit is contained in:
BlockLune 2025-08-19 20:03:13 +08:00
parent 42fc28ba91
commit 90d6de6438
6 changed files with 159 additions and 0 deletions

View file

@ -926,6 +926,9 @@
"wit": {
"revision": "81490b4e74c792369e005f72b0d46fe082d3fed2"
},
"wxml": {
"revision": "4487d2eab73191b93279c98ed31c8e8038c5441f"
},
"xcompose": {
"revision": "fff3e72242aa110ebba6441946ea4d12d200fa68"
},

View file

@ -2667,6 +2667,14 @@ list.wit = {
maintainers = { "@liamwh" },
}
list.wxml = {
install_info = {
url = "https://github.com/BlockLune/tree-sitter-wxml",
files = { "src/parser.c", "src/scanner.c" },
},
maintainers = { "@BlockLune" },
}
list.xcompose = {
install_info = {
url = "https://github.com/ObserverOfTime/tree-sitter-xcompose",

7
queries/wxml/folds.scm Normal file
View file

@ -0,0 +1,7 @@
[
(element)
(template_element)
(slot_element)
(block_element)
(wxs_element)
] @fold

109
queries/wxml/highlights.scm Normal file
View file

@ -0,0 +1,109 @@
; Comments
(comment) @comment
; Document structure
(document) @none
; Elements and tags
(element) @none
(start_tag) @none
(end_tag) @none
(self_closing_tag) @none
; Tag names
(tag_name) @tag
; WeChat Mini Program specific tags
((tag_name) @keyword
(#any-of? @keyword "wxs" "template" "import" "include" "slot" "block"))
; Attributes
(attribute) @none
(attribute_name) @property
(attribute_value) @string
(quoted_attribute_value) @string
; Entity references
(entity) @string.escape
; Text content
(text) @text.literal
; Raw text (primarily for wxs JavaScript content)
(raw_text) @embedded
; Interpolation expressions
(interpolation) @punctuation.special
(expression) @embedded
; Import and include statements
(import_statement) @preproc
(include_statement) @preproc
; Template elements
(template_element) @none
(template_start_tag) @none
(template_end_tag) @none
; Slot elements
(slot_element) @none
(slot_start_tag) @none
(slot_end_tag) @none
; Block elements
(block_element) @none
(block_start_tag) @none
(block_end_tag) @none
; WXS elements (JavaScript modules)
(wxs_element) @none
(wxs_start_tag) @none
(wxs_end_tag) @none
; WeChat specific directive attributes
((attribute_name) @emphasis.strong
(#match? @emphasis.strong "^wx:"))
; Event binding attributes
((attribute_name) @emphasis.strong
(#match? @emphasis.strong "^(bind|catch|mut-bind):?"))
; Data binding attributes
((attribute_name) @emphasis.strong
(#match? @emphasis.strong "^(model:|data-)"))
; Special attributes
((attribute_name) @property.special
(#any-of? @property.special "slot" "is" "module" "src"))
; Punctuation and operators
"<" @punctuation.bracket
">" @punctuation.bracket
"</" @punctuation.bracket
"/>" @punctuation.bracket
"=" @operator
; Quotes in attributes
"\"" @punctuation.delimiter
"'" @punctuation.delimiter

25
queries/wxml/indents.scm Normal file
View file

@ -0,0 +1,25 @@
(start_tag
">" @end) @indent
(self_closing_tag
"/>" @end) @indent
(element
(start_tag) @start
(end_tag)? @end) @indent
(block_element
(block_start_tag) @start
(block_end_tag)? @end) @indent
(slot_element
(slot_start_tag) @start
(slot_end_tag)? @end) @indent
(template_element
(template_start_tag) @start
(template_end_tag)? @end) @indent
(wxs_element
(wxs_start_tag) @start
(wxs_end_tag)? @end) @indent

View file

@ -0,0 +1,7 @@
((raw_text) @injection.content
(#set! injection.language "javascript")
(#set! injection.include-children))
((expression) @injection.content
(#set! injection.language "javascript")
(#set! injection.include-children))