@marko/tree-sitter 0.0.0 → 0.2.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 +1,86 @@
1
- {"name":"@marko/tree-sitter","version":"0.0.0","private":false}
1
+ {
2
+ "name": "@marko/tree-sitter",
3
+ "version": "0.2.0",
4
+ "description": "Tree-sitter grammar for the Marko templating language",
5
+ "keywords": [
6
+ "incremental",
7
+ "marko",
8
+ "parser",
9
+ "tree-sitter"
10
+ ],
11
+ "homepage": "https://github.com/marko-js/tree-sitter",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/marko-js/tree-sitter.git"
15
+ },
16
+ "license": "MIT",
17
+ "publishConfig": {
18
+ "access": "public"
19
+ },
20
+ "engines": {
21
+ "node": ">=18"
22
+ },
23
+ "main": "bindings/node",
24
+ "types": "bindings/node",
25
+ "files": [
26
+ "*.wasm",
27
+ "LICENSE",
28
+ "binding.gyp",
29
+ "bindings/node",
30
+ "grammar.js",
31
+ "prebuilds/**",
32
+ "queries",
33
+ "src/**",
34
+ "tree-sitter.json"
35
+ ],
36
+ "dependencies": {
37
+ "node-addon-api": "^8.3.0",
38
+ "node-gyp-build": "^4.8.4"
39
+ },
40
+ "devDependencies": {
41
+ "@changesets/changelog-github": "^0.7.0",
42
+ "@changesets/cli": "^2.31.0",
43
+ "@types/degit": "^2.8.6",
44
+ "@types/mocha": "^10.0.6",
45
+ "@types/node": "^20.11.16",
46
+ "degit": "^2.8.4",
47
+ "htmljs-parser": "^5.10.2",
48
+ "mocha": "^10.2.0",
49
+ "node-gyp": "^11.0.0",
50
+ "prebuildify": "^6.0.1",
51
+ "tree-sitter": "^0.25.0",
52
+ "tree-sitter-cli": "^0.26.9",
53
+ "tsx": "^4.19.2",
54
+ "web-tree-sitter": "^0.26.9"
55
+ },
56
+ "peerDependencies": {
57
+ "tree-sitter": "^0.25.0"
58
+ },
59
+ "peerDependenciesMeta": {
60
+ "tree-sitter": {
61
+ "optional": true
62
+ }
63
+ },
64
+ "scripts": {
65
+ "build": "tree-sitter generate && node-gyp rebuild",
66
+ "change": "changeset add",
67
+ "generate": "tree-sitter generate",
68
+ "install": "node-gyp-build",
69
+ "release:publish": "changeset publish",
70
+ "release:tag": "changeset tag",
71
+ "test": "mocha \"./__tests__/*.test.mts\"",
72
+ "prebuild": "prebuildify --napi --strip",
73
+ "build:wasm": "tree-sitter build --wasm -o tree-sitter-marko.wasm",
74
+ "test:wasm": "tsx tools/check-wasm.mts",
75
+ "version": "changeset version && node tools/sync-tree-sitter-version.mjs && npm install --package-lock-only"
76
+ },
77
+ "tree-sitter": [
78
+ {
79
+ "scope": "source.marko",
80
+ "file-types": [
81
+ "marko"
82
+ ],
83
+ "injection-regex": "^marko$"
84
+ }
85
+ ]
86
+ }
@@ -0,0 +1,61 @@
1
+ ; Basic syntax highlighting for Marko templates.
2
+
3
+ ; Statement-tag names are not tags visually: static/server/client are
4
+ ; Marko keywords (the compiler strips them before parsing the body as TS),
5
+ ; while import/export/class are part of the injected TS statement itself
6
+ ; and take their color from that injection (see injections.scm).
7
+ ((tag_name (tag_name_fragment) @tag)
8
+ (#not-any-of? @tag "import" "export" "class" "static" "server" "client"))
9
+ ((tag_name (tag_name_fragment) @keyword)
10
+ (#any-of? @keyword "static" "server" "client"))
11
+ (close_tag_name) @tag
12
+ (shorthand_id) @constant
13
+ (shorthand_class) @property
14
+
15
+ (attr_name) @attribute
16
+
17
+ ; Binding positions: patterns get the TS injection; types are captured
18
+ ; flatly because a bare type is not a valid TS program (matching the
19
+ ; tmLanguage grammar's source.ts#type approximation).
20
+ (var_pattern) @variable
21
+ (var_type) @type
22
+ (param_pattern) @variable.parameter
23
+ (param_type) @type
24
+ (param_default) @none
25
+ (type_expr) @type
26
+
27
+ (open_tag_start) @punctuation.bracket
28
+ (open_tag_end) @punctuation.bracket
29
+ (open_tag_end_self) @punctuation.bracket
30
+ (close_tag_start) @punctuation.bracket
31
+ (close_tag_end) @punctuation.bracket
32
+
33
+ (args_open) @punctuation.bracket
34
+ (args_close) @punctuation.bracket
35
+ (params_open) @punctuation.bracket
36
+ (params_close) @punctuation.bracket
37
+ (type_open) @punctuation.bracket
38
+ (type_close) @punctuation.bracket
39
+ (attr_group_open) @punctuation.bracket
40
+ (attr_group_close) @punctuation.bracket
41
+ (method_body_open) @punctuation.bracket
42
+ (method_body_close) @punctuation.bracket
43
+ (scriptlet_block_open) @punctuation.bracket
44
+ (scriptlet_block_close) @punctuation.bracket
45
+
46
+ (placeholder_start) @punctuation.special
47
+ (placeholder_start_raw) @punctuation.special
48
+ (placeholder_end) @punctuation.special
49
+
50
+ (html_comment) @comment
51
+ (line_comment) @comment
52
+ (block_comment) @comment
53
+
54
+ (doctype) @keyword
55
+ (declaration) @keyword
56
+ (cdata) @string
57
+
58
+ (scriptlet_start) @punctuation.special
59
+ (scriptlet_start_concise) @punctuation.special
60
+
61
+ (text) @none
@@ -0,0 +1,123 @@
1
+ ; Embedded-language injections for Marko templates.
2
+ ;
3
+ ; All expression positions in Marko hold TypeScript expressions/statements
4
+ ; (TypeScript is a superset of JavaScript, so it always applies), and
5
+ ; style/script tag bodies hold CSS/TS. These queries let editors parse that
6
+ ; embedded content with the right grammar.
7
+
8
+ ; ${...} / $!{...} placeholders (content + tag name interpolations)
9
+ ((placeholder_expr) @injection.content
10
+ (#set! injection.language "typescript"))
11
+
12
+ ; $ scriptlets: `$ statement` and `$ { block }`
13
+ ((scriptlet_expr) @injection.content
14
+ (#set! injection.language "typescript"))
15
+ ((scriptlet_block_expr) @injection.content
16
+ (#set! injection.language "typescript"))
17
+
18
+ ; Statement tags come in two groups, mirroring how the compiler's core tag
19
+ ; parsers consume them. import/export/class are pass-through TypeScript:
20
+ ; the keyword itself is part of the statement the compiler parses, so the
21
+ ; injection covers the whole element (its trailing tokens are zero-width,
22
+ ; making its extent exactly the statement text, semicolon included).
23
+ ; include-children is required: child node ranges are otherwise excluded
24
+ ; from an injection, and the element's children span its entire text.
25
+ ((element
26
+ (tag_name) @_name
27
+ (#any-of? @_name "import" "export" "class")
28
+ (statement_expr)) @injection.content
29
+ (#set! injection.language "typescript")
30
+ (#set! injection.include-children))
31
+
32
+ ; static/server/client strip their keyword before the body is parsed as
33
+ ; TS, so only the body is injected (the keyword is highlighted as a Marko
34
+ ; keyword in highlights.scm).
35
+ (element
36
+ (tag_name) @_name
37
+ (#any-of? @_name "static" "server" "client")
38
+ (statement_expr) @injection.content
39
+ (#set! injection.language "typescript"))
40
+
41
+ ; attribute values, spreads and bound values
42
+ ((attr_value_expr) @injection.content
43
+ (#set! injection.language "typescript"))
44
+
45
+ ; tag variables and parameters are binding positions: their patterns and
46
+ ; defaults parse cleanly as bare programs, while type annotations are
47
+ ; captured flatly in highlights.scm (a bare type is not a valid TS program).
48
+ ((var_pattern) @injection.content
49
+ (#set! injection.language "typescript"))
50
+ ((param_pattern) @injection.content
51
+ (#set! injection.language "typescript"))
52
+ ((param_default) @injection.content
53
+ (#set! injection.language "typescript"))
54
+
55
+ ; tag/attr arguments and shorthand-method bodies are expression/statement
56
+ ; positions.
57
+ ((args_expr) @injection.content
58
+ (#set! injection.language "typescript"))
59
+ ((method_body_expr) @injection.content
60
+ (#set! injection.language "typescript"))
61
+
62
+ ; <script> bodies: injection.combined merges the raw text chunks split by
63
+ ; ${...} placeholders.
64
+ (element
65
+ (tag_name) @_tag
66
+ (#eq? @_tag "script")
67
+ (text) @injection.content
68
+ (#set! injection.language "typescript")
69
+ (#set! injection.combined))
70
+
71
+ (element
72
+ (tag_name) @_tag
73
+ (#eq? @_tag "html-script")
74
+ (text) @injection.content
75
+ (#set! injection.language "typescript")
76
+ (#set! injection.combined))
77
+
78
+ ; <style> bodies are CSS by default, but shorthand "extension" segments
79
+ ; pick the stylesheet dialect, last segment winning (<style.scss>,
80
+ ; <style.module.scss> -> scss), mirroring the compiler's STYLE_EXT_REG.
81
+ ; The @injection.language capture overrides the #set! fallback, and with
82
+ ; several captured segments the last capture wins.
83
+ (element
84
+ (tag_name) @_tag
85
+ (#eq? @_tag "style")
86
+ (shorthand_class (tag_name_fragment) @injection.language)*
87
+ (text) @injection.content
88
+ (#set! injection.language "css")
89
+ (#set! injection.combined))
90
+
91
+ (element
92
+ (tag_name) @_tag
93
+ (#eq? @_tag "html-style")
94
+ (text) @injection.content
95
+ (#set! injection.language "css")
96
+ (#set! injection.combined))
97
+
98
+ ; style -- css blocks / script -- js blocks in concise mode (the style
99
+ ; form supports the same dialect shorthands: style.scss -- ...).
100
+ ;
101
+ ; Unlike the <script>/<style> forms above, these omit injection.combined: the
102
+ ; concise body is a nested html_block whose lines are separate text nodes, and
103
+ ; Zed desyncs combined injections nested under an html_block on incremental
104
+ ; edits (highlighting blanks out while typing). Per-chunk injection highlights
105
+ ; each line independently, which is fine for these short blocks.
106
+ (element
107
+ (tag_name) @_tag
108
+ (#eq? @_tag "style")
109
+ (shorthand_class (tag_name_fragment) @injection.language)*
110
+ (html_block
111
+ (text) @injection.content)
112
+ (#set! injection.language "css"))
113
+
114
+ (element
115
+ (tag_name) @_tag
116
+ (#eq? @_tag "script")
117
+ (html_block
118
+ (text) @injection.content)
119
+ (#set! injection.language "typescript"))
120
+
121
+ ; html comments
122
+ ((html_comment) @injection.content
123
+ (#set! injection.language "html"))