feat: add xml & dtd parsers

This commit is contained in:
ObserverOfTime 2023-08-04 14:50:28 +03:00
parent 800b2f388b
commit 5b3dd8cff1
12 changed files with 261 additions and 3 deletions

View file

@ -207,6 +207,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [diff](https://github.com/the-mikedavis/tree-sitter-diff) (maintained by @gbprod)
- [x] [dockerfile](https://github.com/camdencheek/tree-sitter-dockerfile) (maintained by @camdencheek)
- [x] [dot](https://github.com/rydesun/tree-sitter-dot) (maintained by @rydesun)
- [x] [dtd](https://github.com/ObserverOfTime/tree-sitter-xml) (maintained by @ObserverOfTime)
- [x] [ebnf](https://github.com/RubixDev/ebnf) (experimental, maintained by @RubixDev)
- [x] [eex](https://github.com/connorlay/tree-sitter-eex) (maintained by @connorlay)
- [x] [elixir](https://github.com/elixir-lang/tree-sitter-elixir) (maintained by @connorlay)
@ -371,6 +372,7 @@ We are looking for maintainers to add more parsers and to write query files for
- [x] [wgsl](https://github.com/szebniok/tree-sitter-wgsl) (maintained by @szebniok)
- [x] [wgsl_bevy](https://github.com/theHamsta/tree-sitter-wgsl-bevy) (maintained by @theHamsta)
- [x] [wing](https://github.com/winglang/wing) (experimental, maintained by @gshpychka)
- [x] [xml](https://github.com/ObserverOfTime/tree-sitter-xml) (maintained by @ObserverOfTime)
- [x] [yaml](https://github.com/ikatyang/tree-sitter-yaml) (maintained by @stsewd)
- [x] [yang](https://github.com/Hubro/tree-sitter-yang) (maintained by @Hubro)
- [x] [yuck](https://github.com/Philipp-M/tree-sitter-yuck) (maintained by @Philipp-M, @amaanq)

View file

@ -101,6 +101,9 @@
"dot": {
"revision": "9ab85550c896d8b294d9b9ca1e30698736f08cea"
},
"dtd": {
"revision": "9deacbfb79cb3527a0396255beb17e1bba3f2052"
},
"ebnf": {
"revision": "8e635b0b723c620774dfb8abf382a7f531894b40"
},
@ -593,6 +596,9 @@
"wing": {
"revision": "9399564d1e32864c6af2d49c0dcd1f76d54443f2"
},
"xml": {
"revision": "9deacbfb79cb3527a0396255beb17e1bba3f2052"
},
"yaml": {
"revision": "0e36bed171768908f331ff7dff9d956bae016efb"
},

View file

@ -42,6 +42,9 @@ for ft, lang in pairs {
quarto = "markdown",
dosini = "ini",
confini = "ini",
svg = "xml",
xsd = "xml",
xslt = "xml",
} do
register_lang(lang, ft)
end
@ -356,6 +359,15 @@ list.dot = {
maintainers = { "@rydesun" },
}
list.dtd = {
install_info = {
url = "https://github.com/ObserverOfTime/tree-sitter-xml",
files = { "src/parser.c", "src/scanner.c" },
location = "tree-sitter-dtd",
},
maintainers = { "@ObserverOfTime" },
}
list.ebnf = {
install_info = {
url = "https://github.com/RubixDev/ebnf",
@ -1745,6 +1757,15 @@ list.wing = {
experimental = true,
}
list.xml = {
install_info = {
url = "https://github.com/ObserverOfTime/tree-sitter-xml",
files = { "src/parser.c", "src/scanner.c" },
location = "tree-sitter-xml",
},
maintainers = { "@ObserverOfTime" },
}
list.yaml = {
install_info = {
url = "https://github.com/ikatyang/tree-sitter-yaml",

4
queries/dtd/folds.scm Normal file
View file

@ -0,0 +1,4 @@
[
(conditionalSect)
(Comment)
] @fold

121
queries/dtd/highlights.scm Normal file
View file

@ -0,0 +1,121 @@
;; XML declaration
(XMLDecl "xml" @preproc)
(XMLDecl [ "version" "encoding" ] @tag.attribute)
(XMLDecl (EncName) @string.special)
(XMLDecl (VersionNum) @number)
;; Processing instructions
(PI) @preproc
;; Element declaration
(elementdecl
"ELEMENT" @define
(Name) @tag)
(contentspec
(_ (Name) @tag.attribute))
"#PCDATA" @type.builtin
[ "EMPTY" "ANY" ] @type.qualifier
[ "*" "?" "+" ] @character.special
;; Entity declaration
(GEDecl
"ENTITY" @define
(Name) @constant)
(GEDecl (EntityValue) @string)
(NDataDecl
"NDATA" @keyword
(Name) @label)
;; Parsed entity declaration
(PEDecl
"ENTITY" @define
"%" @operator
(Name) @function.macro)
(PEDecl (EntityValue) @string)
;; Notation declaration
(NotationDecl
"NOTATION" @preproc
(Name) @label)
((NotationDecl
(ExternalID
(SystemLiteral (URI) @string.special))
(#set! "priority" 105)))
;; Attlist declaration
(AttlistDecl
"ATTLIST" @define
(Name) @tag)
(AttDef (Name) @tag.attribute)
(AttDef (Enumeration (Nmtoken) @string))
[
(StringType)
(TokenizedType)
] @type.builtin
(NotationType "NOTATION" @type.builtin)
[
"#REQUIRED"
"#IMPLIED"
"#FIXED"
] @attribute
;; Entities
(EntityRef) @constant
((EntityRef) @constant.builtin
(#any-of? @constant.builtin
"&" "<" ">" """ "'"))
(CharRef) @character
(PEReference) @function.macro
;; External references
[ "PUBLIC" "SYSTEM" ] @keyword
(PubidLiteral) @string.special
(SystemLiteral (URI) @text.uri)
;; Delimiters & punctuation
[ "<?" "?>" "<!" ">" "]]>" ] @tag.delimiter
[ "(" ")" "[" ] @punctuation.bracket
[ "\"" "'" ] @punctuation.delimiter
[ "," "|" "=" ] @operator
;; Misc
[ "INCLUDE" "IGNORE" ] @include
(Comment) @comment @spell
(ERROR) @error

View file

@ -0,0 +1 @@
(Comment) @comment

View file

@ -4,8 +4,8 @@
((json_body) @injection.content
(#set! injection.language "json"))
; ((xml_body) @injection.content
; (#set! injection.language "xml"))
((xml_body) @injection.content
(#set! injection.language "xml"))
; ((graphql_body) @injection.content
; (#set! injection.language "graphql")) ; Not used as of now..

View file

@ -3,7 +3,7 @@
(#set! injection.language "json"))
((xml) @injection.content
(#set! injection.language "html"))
(#set! injection.language "xml"))
(multiline_string
(multiline_string_type) @_lang

5
queries/xml/folds.scm Normal file
View file

@ -0,0 +1,5 @@
[
(element)
(doctypedecl)
(Comment)
] @fold

View file

@ -0,0 +1,53 @@
; inherits: dtd
;; XML declaration
(XMLDecl "standalone" @tag.attribute)
(XMLDecl [ "yes" "no" ] @boolean)
;; Processing instructions
(XmlModelPI "xml-model" @preproc)
(StyleSheetPI "xml-stylesheet" @preproc)
(PseudoAtt (Name) @tag.attribute)
(PseudoAtt (PseudoAttValue) @string)
;; Doctype declaration
(doctypedecl "DOCTYPE" @define)
(doctypedecl (Name) @type.definition)
;; Tags
(STag (Name) @tag)
(ETag (Name) @tag)
(EmptyElemTag (Name) @tag)
;; Attributes
(Attribute (Name) @tag.attribute)
(Attribute (AttValue) @string)
;; Text
(CharData) @text @spell
((CDSect
(CDStart) @text.environment
(CData) @text.literal
"]]>" @text.environment)
(#set! "priority" 105))
;; Delimiters & punctuation
[ "<" "</" "/>" ] @tag.delimiter
"]" @punctuation.bracket

16
queries/xml/indents.scm Normal file
View file

@ -0,0 +1,16 @@
(element) @indent.begin
[
(Attribute)
(AttlistDecl)
(contentspec)
] @indent.align
(ETag) @indent.dedent
(doctypedecl) @indent.ignore
[
(Comment)
(ERROR)
] @indent.auto

View file

@ -0,0 +1,29 @@
((Comment) @injection.content
(#set! injection.language "comment"))
; SVG style
((element
(STag (Name) @_name)
(content) @injection.content)
(#eq? @_name "style")
(#set! injection.combined)
(#set! injection.include-children)
(#set! injection.language "css"))
; SVG script
((element
(STag (Name) @_name)
(content) @injection.content)
(#eq? @_name "script")
(#set! injection.combined)
(#set! injection.include-children)
(#set! injection.language "javascript"))
; phpMyAdmin dump
((element
(STag (Name) @_name)
(content) @injection.content)
(#eq? @_name "pma:table")
(#set! injection.combined)
(#set! injection.include-children)
(#set! injection.language "sql"))