@willbooster/tree-sitter-xml 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,80 @@
1
1
  {
2
2
  "name": "@willbooster/tree-sitter-xml",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.0.0",
4
+ "description": "XML & DTD grammars for tree-sitter",
5
+ "keywords": [
6
+ "incremental",
7
+ "parsing",
8
+ "tree-sitter",
9
+ "xml",
10
+ "dtd"
11
+ ],
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/WillBooster/tree-sitter-xml.git"
15
+ },
16
+ "license": "MIT",
17
+ "author": "WillBooster Inc.",
18
+ "files": [
19
+ "common/common.mjs",
20
+ "xml/grammar.js",
21
+ "xml/package.json",
22
+ "dtd/grammar.js",
23
+ "dtd/package.json",
24
+ "xml/src/node-types.json",
25
+ "dtd/src/node-types.json",
26
+ "queries/**/*.scm",
27
+ "tree-sitter.json",
28
+ "*.wasm"
29
+ ],
30
+ "scripts": {
31
+ "build-wasm": "script/generate --build-wasm",
32
+ "build/ci": "bun run build-wasm",
33
+ "cleanup": "bun wb lint --fix --format",
34
+ "format": "bun wb lint --format",
35
+ "generate": "script/generate",
36
+ "lint": "bun wb lint",
37
+ "lint-fix": "bun wb lint --fix",
38
+ "prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
39
+ "release": "wb release",
40
+ "prestart": "bun run build-wasm",
41
+ "start": "script/tree-sitter playground",
42
+ "test": "bun wb test",
43
+ "test/ci": "bun wb test-on-ci",
44
+ "test/ci-setup": "playwright install --with-deps chromium",
45
+ "typecheck": "bun wb typecheck",
46
+ "verify": "bun wb verify",
47
+ "verify-full": "bun wb verify --full"
48
+ },
49
+ "devDependencies": {
50
+ "@tsconfig/bun": "1.0.11",
51
+ "@types/bun": "1.4.2",
52
+ "@vitest/browser-playwright": "5.0.3",
53
+ "@willbooster/oxfmt-config": "1.2.2",
54
+ "@willbooster/oxlint-config": "1.4.8",
55
+ "@willbooster/wb": "22.26.1",
56
+ "@willbooster/web-tree-sitter": "2.0.28",
57
+ "conventional-changelog-conventionalcommits": "10.4.0",
58
+ "lefthook": "2.2.1",
59
+ "oxfmt": "0.72.0",
60
+ "oxlint": "1.87.0",
61
+ "oxlint-tsgolint": "7.0.2004",
62
+ "playwright": "1.63.0",
63
+ "semantic-release": "25.0.9",
64
+ "sort-package-json": "4.0.0",
65
+ "vitest": "5.0.3",
66
+ "wrangler": "4.147.0"
67
+ },
68
+ "peerDependencies": {
69
+ "@willbooster/web-tree-sitter": "^2.0.0"
70
+ },
71
+ "peerDependenciesMeta": {
72
+ "@willbooster/web-tree-sitter": {
73
+ "optional": true
74
+ }
75
+ },
76
+ "publishConfig": {
77
+ "access": "public",
78
+ "registry": "https://registry.npmjs.org/"
79
+ }
80
+ }
@@ -0,0 +1,129 @@
1
+ ;; XML declaration
2
+
3
+ "xml" @keyword
4
+
5
+ [ "version" "encoding" ] @property
6
+
7
+ (EncName) @string.special
8
+
9
+ (VersionNum) @number
10
+
11
+ ;; Processing instructions
12
+
13
+ (PI) @embedded
14
+
15
+ (PI (PITarget) @keyword)
16
+
17
+ ;; Element declaration
18
+
19
+ (elementdecl
20
+ "ELEMENT" @keyword
21
+ (Name) @tag)
22
+
23
+ (contentspec
24
+ (_ (Name) @property))
25
+
26
+ "#PCDATA" @type.builtin
27
+
28
+ [ "EMPTY" "ANY" ] @string.special.symbol
29
+
30
+ [ "*" "?" "+" ] @operator
31
+
32
+ ;; Entity declaration
33
+
34
+ (GEDecl
35
+ "ENTITY" @keyword
36
+ (Name) @constant)
37
+
38
+ (GEDecl (EntityValue) @string)
39
+
40
+ (NDataDecl
41
+ "NDATA" @keyword
42
+ (Name) @label)
43
+
44
+ ;; Parsed entity declaration
45
+
46
+ (PEDecl
47
+ "ENTITY" @keyword
48
+ "%" @operator
49
+ (Name) @constant)
50
+
51
+ (PEDecl (EntityValue) @string)
52
+
53
+ ;; Notation declaration
54
+
55
+ (NotationDecl
56
+ "NOTATION" @keyword
57
+ (Name) @constant)
58
+
59
+ (NotationDecl
60
+ (ExternalID
61
+ (SystemLiteral (URI) @string.special)))
62
+
63
+ ;; Attlist declaration
64
+
65
+ (AttlistDecl
66
+ "ATTLIST" @keyword
67
+ (Name) @tag)
68
+
69
+ (AttDef (Name) @property)
70
+
71
+ (AttDef (Enumeration (Nmtoken) @string))
72
+
73
+ (DefaultDecl (AttValue) @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
+ ;; Delimiters & punctuation
109
+
110
+ [
111
+ "<?" "?>"
112
+ "<!" ">"
113
+ "<![" "]]>"
114
+ ] @punctuation.delimiter
115
+
116
+ [ "(" ")" "[" ] @punctuation.bracket
117
+
118
+ [ "\"" "'" ] @punctuation.delimiter
119
+
120
+ [ "," "|" "=" ] @operator
121
+
122
+ ;; Misc
123
+
124
+ ; FIXME: enable when ts test is fixed
125
+ ; [ "INCLUDE" "IGNORE" ] @keyword
126
+
127
+ (Comment) @comment
128
+
129
+ (ERROR) @error
@@ -0,0 +1,168 @@
1
+ ;; XML declaration
2
+
3
+ "xml" @keyword
4
+
5
+ [ "version" "encoding" "standalone" ] @property
6
+
7
+ (EncName) @string.special
8
+
9
+ (VersionNum) @number
10
+
11
+ [ "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.special.symbol
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
+ (DefaultDecl (AttValue) @string)
76
+
77
+ [
78
+ (StringType)
79
+ (TokenizedType)
80
+ ] @type.builtin
81
+
82
+ (NotationType "NOTATION" @type.builtin)
83
+
84
+ [
85
+ "#REQUIRED"
86
+ "#IMPLIED"
87
+ "#FIXED"
88
+ ] @attribute
89
+
90
+ ;; Entities
91
+
92
+ (EntityRef) @constant
93
+
94
+ ((EntityRef) @constant.builtin
95
+ (#any-of? @constant.builtin
96
+ "&amp;" "&lt;" "&gt;" "&quot;" "&apos;"))
97
+
98
+ (CharRef) @constant
99
+
100
+ (PEReference) @constant
101
+
102
+ ;; External references
103
+
104
+ [ "PUBLIC" "SYSTEM" ] @keyword
105
+
106
+ (PubidLiteral) @string.special
107
+
108
+ (SystemLiteral (URI) @markup.link)
109
+
110
+ ;; Processing instructions
111
+
112
+ (XmlModelPI "xml-model" @keyword)
113
+
114
+ (StyleSheetPI "xml-stylesheet" @keyword)
115
+
116
+ (PseudoAtt (Name) @property)
117
+
118
+ (PseudoAtt (PseudoAttValue) @string)
119
+
120
+ ;; Doctype declaration
121
+
122
+ (doctypedecl "DOCTYPE" @keyword)
123
+
124
+ (doctypedecl (Name) @type)
125
+
126
+ ;; Tags
127
+
128
+ (STag (Name) @tag)
129
+
130
+ (ETag (Name) @tag)
131
+
132
+ (EmptyElemTag (Name) @tag)
133
+
134
+ ;; Attributes
135
+
136
+ (Attribute (Name) @property)
137
+
138
+ (Attribute (AttValue) @string)
139
+
140
+ ;; Delimiters & punctuation
141
+
142
+ [
143
+ "<?" "?>"
144
+ "<!" "]]>"
145
+ "<" ">"
146
+ "</" "/>"
147
+ ] @punctuation.delimiter
148
+
149
+ [ "(" ")" "[" "]" ] @punctuation.bracket
150
+
151
+ [ "\"" "'" ] @punctuation.delimiter
152
+
153
+ [ "," "|" "=" ] @operator
154
+
155
+ ;; Text
156
+
157
+ (CharData) @markup
158
+
159
+ (CDSect
160
+ (CDStart) @markup.heading
161
+ (CData) @markup.raw
162
+ "]]>" @markup.heading)
163
+
164
+ ;; Misc
165
+
166
+ (Comment) @comment
167
+
168
+ (ERROR) @error
Binary file
Binary file
@@ -0,0 +1,61 @@
1
+ {
2
+ "$schema": "https://tree-sitter.github.io/tree-sitter/assets/schemas/config.schema.json",
3
+ "grammars": [
4
+ {
5
+ "name": "xml",
6
+ "camelcase": "XML",
7
+ "scope": "source.xml",
8
+ "path": "xml",
9
+ "external-files": [
10
+ "common/scanner.h"
11
+ ],
12
+ "file-types": [
13
+ "xml",
14
+ "svg",
15
+ "xsd",
16
+ "xslt",
17
+ "xsl",
18
+ "rng"
19
+ ],
20
+ "highlights": "queries/xml/highlights.scm",
21
+ "injection-regex": "^(xml|svg|xsd|xslt|xsl|rng)$"
22
+ },
23
+ {
24
+ "name": "dtd",
25
+ "camelcase": "DTD",
26
+ "scope": "source.dtd",
27
+ "path": "dtd",
28
+ "external-files": [
29
+ "common/scanner.h"
30
+ ],
31
+ "file-types": [
32
+ "dtd"
33
+ ],
34
+ "highlights": "queries/dtd/highlights.scm",
35
+ "injection-regex": "^dtd$"
36
+ }
37
+ ],
38
+ "metadata": {
39
+ "version": "1.0.0",
40
+ "license": "MIT",
41
+ "description": "XML & DTD grammars for tree-sitter",
42
+ "authors": [
43
+ {
44
+ "name": "WillBooster Inc."
45
+ }
46
+ ],
47
+ "links": {
48
+ "repository": "https://github.com/WillBooster/tree-sitter-xml"
49
+ }
50
+ },
51
+ "bindings": {
52
+ "c": false,
53
+ "go": false,
54
+ "java": false,
55
+ "node": false,
56
+ "python": false,
57
+ "rust": true,
58
+ "swift": false,
59
+ "zig": false
60
+ }
61
+ }
package/xml/grammar.js ADDED
@@ -0,0 +1,196 @@
1
+ /**
2
+ * @file Tree-sitter grammar definition for XML
3
+ * @author ObserverOfTime
4
+ * @license MIT
5
+ */
6
+
7
+ /// <reference types="tree-sitter-cli/dsl" />
8
+ // @ts-check
9
+
10
+ import * as c from '../common/common.mjs';
11
+
12
+ const O = optional;
13
+
14
+ export default grammar({
15
+ name: 'xml',
16
+
17
+ externals: $ => [
18
+ // DTD
19
+ $.PITarget,
20
+ $._pi_content,
21
+ $.Comment,
22
+
23
+ // XML
24
+ $.CharData,
25
+ $.CData,
26
+ 'xml-model',
27
+ 'xml-stylesheet',
28
+ $._start_tag_name,
29
+ $._end_tag_name,
30
+ $._erroneous_end_name,
31
+ '/>',
32
+ ],
33
+
34
+ extras: _ => [],
35
+
36
+ supertypes: $ => [
37
+ $._markupdecl,
38
+ $._AttType,
39
+ $._EnumeratedType,
40
+ $._EntityDecl,
41
+ $._Reference,
42
+ ],
43
+
44
+ conflicts: $ => [
45
+ [$.AttlistDecl, $.AttDef]
46
+ ],
47
+
48
+ word: $ => $.Name,
49
+
50
+ rules: {
51
+ document: $ => prec(2, seq(
52
+ O($._S),
53
+ O($.prolog),
54
+ field('root', $.element),
55
+ repeat($._Misc),
56
+ )),
57
+
58
+ prolog: $ => choice(
59
+ seq(
60
+ $.XMLDecl,
61
+ repeat($._Misc),
62
+ ),
63
+ seq(
64
+ O($.XMLDecl),
65
+ repeat($._Misc),
66
+ $.doctypedecl,
67
+ repeat($._Misc),
68
+ ),
69
+ repeat1($._Misc)
70
+ ),
71
+
72
+ _Misc: $ => choice(
73
+ $.PI,
74
+ $.StyleSheetPI,
75
+ $.XmlModelPI,
76
+ $.Comment,
77
+ $._S
78
+ ),
79
+
80
+ XMLDecl: $ => seq(
81
+ '<?',
82
+ 'xml',
83
+ $._VersionInfo,
84
+ O($._EncodingDecl),
85
+ O($._SDDecl),
86
+ O($._S),
87
+ '?>'
88
+ ),
89
+
90
+ _SDDecl: $ => seq(
91
+ $._S,
92
+ 'standalone',
93
+ $._Eq,
94
+ c.str(choice('yes', 'no'))
95
+ ),
96
+
97
+ doctypedecl: $ => seq(
98
+ '<!',
99
+ 'DOCTYPE',
100
+ $._S,
101
+ $.Name,
102
+ O(seq($._S, $.ExternalID)),
103
+ O($._S),
104
+ O(seq(
105
+ '[',
106
+ O(choice(
107
+ $._intSubset,
108
+ $._S
109
+ )),
110
+ ']',
111
+ O($._S)
112
+ )),
113
+ '>'
114
+ ),
115
+
116
+ _intSubset: $ => c.rseq1(
117
+ O($._S),
118
+ $._markupdecl,
119
+ $._DeclSep
120
+ ),
121
+
122
+ element: $ => choice(
123
+ $.EmptyElemTag,
124
+ seq($.STag, O($.content), $.ETag)
125
+ ),
126
+
127
+ EmptyElemTag: $ => seq(
128
+ '<',
129
+ alias($._start_tag_name, $.Name),
130
+ c.rseq($._S, $.Attribute),
131
+ O($._S),
132
+ '/>'
133
+ ),
134
+
135
+ Attribute: $ => seq($.Name, $._Eq, $.AttValue),
136
+
137
+ STag: $ => seq(
138
+ '<',
139
+ alias($._start_tag_name, $.Name),
140
+ c.rseq($._S, $.Attribute),
141
+ O($._S),
142
+ '>'
143
+ ),
144
+
145
+ ETag: $ => seq('</', alias($._end_tag_name, $.Name), O($._S), '>'),
146
+
147
+ _ErroneousETag: $ => seq(
148
+ '</',
149
+ alias($._erroneous_end_name, $.ERROR),
150
+ O($._S),
151
+ '>',
152
+ ),
153
+
154
+ content: $ => repeat1(
155
+ choice(
156
+ $.CharData,
157
+ $.element,
158
+ $._Reference,
159
+ $.CDSect,
160
+ $.PI,
161
+ $.Comment
162
+ )
163
+ ),
164
+
165
+ CDSect: $ => prec.left(
166
+ seq($.CDStart, optional($.CData), ']]>')
167
+ ),
168
+
169
+ CDStart: _ => seq('<![', 'CDATA', '['),
170
+
171
+ StyleSheetPI: $ => seq(
172
+ '<?',
173
+ 'xml-stylesheet',
174
+ c.rseq($._S, $.PseudoAtt),
175
+ O($._S),
176
+ '?>'
177
+ ),
178
+
179
+ XmlModelPI: $ => seq(
180
+ '<?',
181
+ 'xml-model',
182
+ c.rseq($._S, $.PseudoAtt),
183
+ O($._S),
184
+ '?>'
185
+ ),
186
+
187
+ PseudoAtt: $ => seq($.Name, $._Eq, $.PseudoAttValue),
188
+
189
+ PseudoAttValue: $ => choice(
190
+ c.att_value($, '"'),
191
+ c.att_value($, "'")
192
+ ),
193
+
194
+ ...c.rules
195
+ }
196
+ });
@@ -0,0 +1,4 @@
1
+ {
2
+ "private": true,
3
+ "type": "module"
4
+ }