tree-sitter-fd 0.1.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/grammar.js +145 -0
- package/package.json +37 -0
- package/queries/highlights.scm +49 -0
- package/src/grammar.json +603 -0
- package/src/node-types.json +563 -0
- package/src/parser.c +6119 -0
- package/src/tree_sitter/alloc.h +54 -0
- package/src/tree_sitter/array.h +291 -0
- package/src/tree_sitter/parser.h +266 -0
package/grammar.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/// <reference types="tree-sitter-cli/dsl" />
|
|
2
|
+
// @ts-check
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Tree-sitter grammar for FD (Fast Draft) format.
|
|
6
|
+
*
|
|
7
|
+
* FD is a token-efficient format for describing 2D scene graphs
|
|
8
|
+
* with shapes, text, styles, animations, and constraints.
|
|
9
|
+
*/
|
|
10
|
+
module.exports = grammar({
|
|
11
|
+
name: "fd",
|
|
12
|
+
|
|
13
|
+
extras: ($) => [/\s/, $.comment],
|
|
14
|
+
|
|
15
|
+
rules: {
|
|
16
|
+
// ─── Document ────────────────────────────────────────────
|
|
17
|
+
document: ($) =>
|
|
18
|
+
repeat(
|
|
19
|
+
choice(
|
|
20
|
+
$.style_block,
|
|
21
|
+
$.node_declaration,
|
|
22
|
+
$.constraint_line,
|
|
23
|
+
$.annotation,
|
|
24
|
+
),
|
|
25
|
+
),
|
|
26
|
+
|
|
27
|
+
// ─── Comments ────────────────────────────────────────────
|
|
28
|
+
comment: (_$) => token(prec(-1, seq("#", /[^#\n][^\n]*/))),
|
|
29
|
+
|
|
30
|
+
// ─── Annotations ─────────────────────────────────────────
|
|
31
|
+
annotation: ($) =>
|
|
32
|
+
seq(
|
|
33
|
+
"##",
|
|
34
|
+
optional(
|
|
35
|
+
choice($.annotation_typed, $.string, $.annotation_text),
|
|
36
|
+
),
|
|
37
|
+
),
|
|
38
|
+
|
|
39
|
+
annotation_typed: ($) =>
|
|
40
|
+
seq(
|
|
41
|
+
field("key", $.annotation_keyword),
|
|
42
|
+
":",
|
|
43
|
+
field("value", choice($.string, $.annotation_text)),
|
|
44
|
+
),
|
|
45
|
+
|
|
46
|
+
annotation_text: (_$) => /[^\n]+/,
|
|
47
|
+
|
|
48
|
+
annotation_keyword: (_$) =>
|
|
49
|
+
choice("accept", "status", "priority", "tag"),
|
|
50
|
+
|
|
51
|
+
// ─── Style Block ─────────────────────────────────────────
|
|
52
|
+
style_block: ($) =>
|
|
53
|
+
seq(
|
|
54
|
+
"style",
|
|
55
|
+
field("name", $.identifier),
|
|
56
|
+
"{",
|
|
57
|
+
repeat($.property),
|
|
58
|
+
"}",
|
|
59
|
+
),
|
|
60
|
+
|
|
61
|
+
// ─── Node Declaration ────────────────────────────────────
|
|
62
|
+
node_declaration: ($) =>
|
|
63
|
+
seq(
|
|
64
|
+
field("kind", $.node_kind),
|
|
65
|
+
optional(field("id", $.node_id)),
|
|
66
|
+
optional(field("inline_text", $.string)),
|
|
67
|
+
"{",
|
|
68
|
+
repeat($.node_body_item),
|
|
69
|
+
"}",
|
|
70
|
+
),
|
|
71
|
+
|
|
72
|
+
node_kind: (_$) => choice("group", "rect", "ellipse", "path", "text"),
|
|
73
|
+
|
|
74
|
+
node_body_item: ($) =>
|
|
75
|
+
choice(
|
|
76
|
+
$.property,
|
|
77
|
+
$.node_declaration,
|
|
78
|
+
$.anim_block,
|
|
79
|
+
$.annotation,
|
|
80
|
+
),
|
|
81
|
+
|
|
82
|
+
// ─── Properties ──────────────────────────────────────────
|
|
83
|
+
property: ($) =>
|
|
84
|
+
prec.right(seq(
|
|
85
|
+
field("name", $.property_name),
|
|
86
|
+
":",
|
|
87
|
+
repeat1($._value_item),
|
|
88
|
+
)),
|
|
89
|
+
|
|
90
|
+
property_name: (_$) =>
|
|
91
|
+
choice(
|
|
92
|
+
"w", "h", "width", "height",
|
|
93
|
+
"fill", "stroke", "corner", "opacity",
|
|
94
|
+
"font", "bg", "use", "layout",
|
|
95
|
+
"shadow", "scale", "rotate", "translate",
|
|
96
|
+
"center_in", "offset", "ease", "duration",
|
|
97
|
+
),
|
|
98
|
+
|
|
99
|
+
_value_item: ($) =>
|
|
100
|
+
choice(
|
|
101
|
+
$.number,
|
|
102
|
+
$.hex_color,
|
|
103
|
+
$.string,
|
|
104
|
+
$.node_id,
|
|
105
|
+
$.key_value_pair,
|
|
106
|
+
$.identifier,
|
|
107
|
+
),
|
|
108
|
+
|
|
109
|
+
key_value_pair: ($) =>
|
|
110
|
+
prec(1, seq($.identifier, "=", choice($.number, $.hex_color, $.string, $.identifier))),
|
|
111
|
+
|
|
112
|
+
// ─── Animation Block ─────────────────────────────────────
|
|
113
|
+
anim_block: ($) =>
|
|
114
|
+
seq(
|
|
115
|
+
"anim",
|
|
116
|
+
field("trigger", $.anim_trigger),
|
|
117
|
+
"{",
|
|
118
|
+
repeat($.property),
|
|
119
|
+
"}",
|
|
120
|
+
),
|
|
121
|
+
|
|
122
|
+
anim_trigger: ($) => seq(":", $.identifier),
|
|
123
|
+
|
|
124
|
+
// ─── Constraint Line ─────────────────────────────────────
|
|
125
|
+
constraint_line: ($) =>
|
|
126
|
+
prec.right(seq(
|
|
127
|
+
field("target", $.node_id),
|
|
128
|
+
"->",
|
|
129
|
+
field("constraint_type", $.identifier),
|
|
130
|
+
":",
|
|
131
|
+
repeat1($._value_item),
|
|
132
|
+
)),
|
|
133
|
+
|
|
134
|
+
// ─── Literals ────────────────────────────────────────────
|
|
135
|
+
node_id: ($) => seq("@", $.identifier),
|
|
136
|
+
|
|
137
|
+
identifier: (_$) => /[a-zA-Z_][a-zA-Z0-9_]*/,
|
|
138
|
+
|
|
139
|
+
number: (_$) => /-?\d+(\.\d+)?(ms)?/,
|
|
140
|
+
|
|
141
|
+
hex_color: (_$) => /#[0-9A-Fa-f]{3,8}/,
|
|
142
|
+
|
|
143
|
+
string: (_$) => seq('"', /[^"]*/, '"'),
|
|
144
|
+
},
|
|
145
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-sitter-fd",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tree-sitter grammar for FD (Fast Draft) files",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Khang Nghiêm",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/khangnghiem/fast-draft"
|
|
10
|
+
},
|
|
11
|
+
"main": "bindings/node",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"tree-sitter",
|
|
14
|
+
"fd",
|
|
15
|
+
"fast-draft",
|
|
16
|
+
"parser"
|
|
17
|
+
],
|
|
18
|
+
"files": [
|
|
19
|
+
"grammar.js",
|
|
20
|
+
"binding.gyp",
|
|
21
|
+
"prebuilds/**",
|
|
22
|
+
"bindings/node/*",
|
|
23
|
+
"queries/*",
|
|
24
|
+
"src/**"
|
|
25
|
+
],
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"nan": "^2.18.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"tree-sitter-cli": "^0.24.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tree-sitter generate && node-gyp build",
|
|
34
|
+
"test": "tree-sitter test",
|
|
35
|
+
"parse": "tree-sitter parse"
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
; FD (Fast Draft) — Tree-sitter highlight queries
|
|
2
|
+
; For use with Zed, Neovim, Helix, Emacs, etc.
|
|
3
|
+
|
|
4
|
+
; ─── Comments ──────────────────────────────────────────────
|
|
5
|
+
(comment) @comment
|
|
6
|
+
|
|
7
|
+
; ─── Keywords ──────────────────────────────────────────────
|
|
8
|
+
(node_kind) @keyword
|
|
9
|
+
"style" @keyword
|
|
10
|
+
"anim" @keyword
|
|
11
|
+
|
|
12
|
+
; ─── Node IDs ──────────────────────────────────────────────
|
|
13
|
+
(node_id
|
|
14
|
+
(identifier) @variable)
|
|
15
|
+
(node_id) @variable
|
|
16
|
+
|
|
17
|
+
; ─── Properties ────────────────────────────────────────────
|
|
18
|
+
(property_name) @property
|
|
19
|
+
|
|
20
|
+
; ─── Annotations ───────────────────────────────────────────
|
|
21
|
+
"##" @attribute
|
|
22
|
+
(annotation_keyword) @attribute
|
|
23
|
+
|
|
24
|
+
; ─── Animation trigger ─────────────────────────────────────
|
|
25
|
+
(anim_trigger
|
|
26
|
+
(identifier) @label)
|
|
27
|
+
|
|
28
|
+
; ─── Constraint arrow ──────────────────────────────────────
|
|
29
|
+
"->" @operator
|
|
30
|
+
|
|
31
|
+
; ─── Literals ──────────────────────────────────────────────
|
|
32
|
+
(number) @number
|
|
33
|
+
(hex_color) @constant.builtin
|
|
34
|
+
(string) @string
|
|
35
|
+
|
|
36
|
+
; ─── Key-value pairs ───────────────────────────────────────
|
|
37
|
+
(key_value_pair
|
|
38
|
+
key: (identifier) @property)
|
|
39
|
+
|
|
40
|
+
; ─── Identifiers (layout modes, easing, etc.) ─────────────
|
|
41
|
+
(property_value
|
|
42
|
+
(identifier) @constant)
|
|
43
|
+
|
|
44
|
+
; ─── Punctuation ───────────────────────────────────────────
|
|
45
|
+
"{" @punctuation.bracket
|
|
46
|
+
"}" @punctuation.bracket
|
|
47
|
+
":" @punctuation.delimiter
|
|
48
|
+
"," @punctuation.delimiter
|
|
49
|
+
"=" @operator
|