Skip to content

Commit 5f29f0e

Browse files
authored
feat: Add XML support (#222)
* feat: Add XML support * Specify path * Specify path * Update CHANGELOG.md
1 parent b3818c9 commit 5f29f0e

File tree

6 files changed

+181
-0
lines changed

6 files changed

+181
-0
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,3 +346,9 @@
346346
branch = main
347347
update = none
348348
ignore = dirty
349+
[submodule "repos/xml"]
350+
path = repos/xml
351+
url = https://github.com/ObserverOfTime/tree-sitter-xml
352+
branch = master
353+
update = none
354+
ignore = dirty

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Add `Xml` support
45

56
## 0.12.36 - 2023-09-02
67
- Add `VHDL` support

queries/xml/highlights.scm

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
;; XML declaration
2+
3+
(XMLDecl "xml" @keyword)
4+
5+
(XMLDecl [ "version" "encoding" "standalone" ] @property)
6+
7+
(XMLDecl (EncName) @string.special)
8+
9+
(XMLDecl (VersionNum) @number)
10+
11+
(XMLDecl [ "yes" "no" ] @boolean)
12+
13+
;; Processing instructions
14+
15+
(PI) @embedded
16+
17+
(PI (PITarget) @keyword)
18+
19+
;; Element declaration
20+
21+
(elementdecl
22+
"ELEMENT" @keyword
23+
(Name) @tag)
24+
25+
(contentspec
26+
(_ (Name) @property))
27+
28+
"#PCDATA" @type.builtin
29+
30+
[ "EMPTY" "ANY" ] @string
31+
32+
[ "*" "?" "+" ] @operator
33+
34+
;; Entity declaration
35+
36+
(GEDecl
37+
"ENTITY" @keyword
38+
(Name) @constant)
39+
40+
(GEDecl (EntityValue) @string)
41+
42+
(NDataDecl
43+
"NDATA" @keyword
44+
(Name) @label)
45+
46+
;; Parsed entity declaration
47+
48+
(PEDecl
49+
"ENTITY" @keyword
50+
"%" @operator
51+
(Name) @constant)
52+
53+
(PEDecl (EntityValue) @string)
54+
55+
;; Notation declaration
56+
57+
(NotationDecl
58+
"NOTATION" @keyword
59+
(Name) @constant)
60+
61+
(NotationDecl
62+
(ExternalID
63+
(SystemLiteral (URI) @string.special)))
64+
65+
;; Attlist declaration
66+
67+
(AttlistDecl
68+
"ATTLIST" @keyword
69+
(Name) @tag)
70+
71+
(AttDef (Name) @property)
72+
73+
(AttDef (Enumeration (Nmtoken) @string))
74+
75+
[
76+
(StringType)
77+
(TokenizedType)
78+
] @type.builtin
79+
80+
(NotationType "NOTATION" @type.builtin)
81+
82+
[
83+
"#REQUIRED"
84+
"#IMPLIED"
85+
"#FIXED"
86+
] @attribute
87+
88+
;; Entities
89+
90+
(EntityRef) @constant
91+
92+
((EntityRef) @constant.builtin
93+
(#any-of? @constant.builtin
94+
"&" "<" ">" """ "'"))
95+
96+
(CharRef) @constant
97+
98+
(PEReference) @constant
99+
100+
;; External references
101+
102+
[ "PUBLIC" "SYSTEM" ] @keyword
103+
104+
(PubidLiteral) @string.special
105+
106+
(SystemLiteral (URI) @markup.link)
107+
108+
;; Processing instructions
109+
110+
(XmlModelPI "xml-model" @keyword)
111+
112+
(StyleSheetPI "xml-stylesheet" @keyword)
113+
114+
(PseudoAtt (Name) @property)
115+
116+
(PseudoAtt (PseudoAttValue) @string)
117+
118+
;; Doctype declaration
119+
120+
(doctypedecl "DOCTYPE" @keyword)
121+
122+
(doctypedecl (Name) @type)
123+
124+
;; Tags
125+
126+
(STag (Name) @tag)
127+
128+
(ETag (Name) @tag)
129+
130+
(EmptyElemTag (Name) @tag)
131+
132+
;; Attributes
133+
134+
(Attribute (Name) @property)
135+
136+
(Attribute (AttValue) @string)
137+
138+
;; Text
139+
140+
(CharData) @markup
141+
142+
(CDSect
143+
(CDStart) @markup.heading
144+
(CData) @markup.raw
145+
"]]>" @markup.heading)
146+
147+
;; Delimiters & punctuation
148+
149+
[
150+
"<?" "?>"
151+
"<!" "]]>"
152+
"<" ">"
153+
"</" "/>"
154+
] @punctuation.delimiter
155+
156+
[
157+
"(" ")"
158+
"[" "]"
159+
] @punctuation.bracket
160+
161+
[ "\"" "'" ] @punctuation.delimiter
162+
163+
[ "," "|" "=" ] @operator
164+
165+
;; Misc
166+
167+
[ "INCLUDE" "IGNORE" ] @keyword
168+
169+
(Comment) @comment
170+
171+
(ERROR) @error

repos/xml

Submodule xml added at 9deacbf

tree-sitter-langs-build.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ git checkout."
160160
;; XXX
161161
('typescript '("typescript" ("tsx" . tsx)))
162162
('ocaml '("ocaml" ("interface" . ocaml-interface)))
163+
('xml '("tree-sitter-xml" ("tree-sitter-dtd" . dtd)))
163164
(_ '("")))))))
164165

165166
(defun tree-sitter-langs--repo-status (lang-symbol)

tree-sitter-langs.el

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ See `tree-sitter-langs-repos'."
162162
(typescript-mode . typescript)
163163
(verilog-mode . verilog)
164164
(vhdl-mode . vhdl)
165+
(nxml-mode . xml)
165166
(yaml-mode . yaml)
166167
(zig-mode . zig))))
167168
(cl-pushnew entry tree-sitter-major-mode-language-alist

0 commit comments

Comments
 (0)