tree-sitter-muttrc 0.0.1
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/.cmake-format.yaml +2 -0
- package/.cmakelintrc +1 -0
- package/.github/FUNDING.yml +6 -0
- package/.github/workflows/main.yml +152 -0
- package/.gitlint +5 -0
- package/.pre-commit-config.yaml +112 -0
- package/.yamllint.yaml +8 -0
- package/CMakeLists.txt +38 -0
- package/Cargo.toml +26 -0
- package/README.md +83 -0
- package/binding.gyp +16 -0
- package/bindings/node/binding.cc +28 -0
- package/bindings/node/index.js +19 -0
- package/bindings/python/tree_sitter_muttrc/__init__.py +42 -0
- package/bindings/python/tree_sitter_muttrc/__main__.py +60 -0
- package/bindings/python/tree_sitter_muttrc/py.typed +0 -0
- package/bindings/rust/build.rs +40 -0
- package/bindings/rust/lib.rs +52 -0
- package/grammar.js +520 -0
- package/package.json +28 -0
- package/pyproject.toml +124 -0
- package/queries/highlights.scm +53 -0
- package/queries/injections.scm +8 -0
- package/requirements/colorize.txt +3 -0
- package/requirements/dev.txt +4 -0
- package/requirements.txt +3 -0
- package/scripts/build.sh +8 -0
- package/src/grammar.json +3905 -0
- package/src/node-types.json +7353 -0
- package/src/parser.c +20578 -0
- package/src/tree_sitter/parser.h +224 -0
- package/templates/class.txt +2 -0
- package/templates/def.txt +12 -0
- package/templates/noarg.txt +1 -0
- package/test/corpus/example.txt +82 -0
- package/tests/neomuttrc +20 -0
- package/tests/test___init__.py +22 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//! This crate provides muttrc language support for the [tree-sitter][] parsing library.
|
|
2
|
+
//!
|
|
3
|
+
//! Typically, you will use the [language][language func] function to add this language to a
|
|
4
|
+
//! tree-sitter [Parser][], and then use the parser to parse some code:
|
|
5
|
+
//!
|
|
6
|
+
//! ```
|
|
7
|
+
//! let code = "";
|
|
8
|
+
//! let mut parser = tree_sitter::Parser::new();
|
|
9
|
+
//! parser.set_language(tree_sitter_muttrc::language()).expect("Error loading muttrc grammar");
|
|
10
|
+
//! let tree = parser.parse(code, None).unwrap();
|
|
11
|
+
//! ```
|
|
12
|
+
//!
|
|
13
|
+
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
14
|
+
//! [language func]: fn.language.html
|
|
15
|
+
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
|
|
16
|
+
//! [tree-sitter]: https://tree-sitter.github.io/
|
|
17
|
+
|
|
18
|
+
use tree_sitter::Language;
|
|
19
|
+
|
|
20
|
+
extern "C" {
|
|
21
|
+
fn tree_sitter_muttrc() -> Language;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/// Get the tree-sitter [Language][] for this grammar.
|
|
25
|
+
///
|
|
26
|
+
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
|
|
27
|
+
pub fn language() -> Language {
|
|
28
|
+
unsafe { tree_sitter_muttrc() }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/// The content of the [`node-types.json`][] file for this grammar.
|
|
32
|
+
///
|
|
33
|
+
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
|
|
34
|
+
pub const NODE_TYPES: &'static str = include_str!("../../src/node-types.json");
|
|
35
|
+
|
|
36
|
+
// Uncomment these to include any queries that this grammar contains
|
|
37
|
+
|
|
38
|
+
// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
|
|
39
|
+
// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm");
|
|
40
|
+
// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
|
|
41
|
+
// pub const TAGS_QUERY: &'static str = include_str!("../../queries/tags.scm");
|
|
42
|
+
|
|
43
|
+
#[cfg(test)]
|
|
44
|
+
mod tests {
|
|
45
|
+
#[test]
|
|
46
|
+
fn test_can_load_grammar() {
|
|
47
|
+
let mut parser = tree_sitter::Parser::new();
|
|
48
|
+
parser
|
|
49
|
+
.set_language(super::language())
|
|
50
|
+
.expect("Error loading muttrc language");
|
|
51
|
+
}
|
|
52
|
+
}
|
package/grammar.js
ADDED
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
module.exports = grammar({
|
|
2
|
+
name: "muttrc",
|
|
3
|
+
|
|
4
|
+
extras: (_) => [/\s/, /\\\r?\n/],
|
|
5
|
+
|
|
6
|
+
rules: {
|
|
7
|
+
file: ($) => repeat(seq(optional($._command), $._end)),
|
|
8
|
+
|
|
9
|
+
_command: ($) =>
|
|
10
|
+
choice(
|
|
11
|
+
$.alias_directive,
|
|
12
|
+
$.alternates_directive,
|
|
13
|
+
$.alternative_order_directive,
|
|
14
|
+
$.attachments_directive,
|
|
15
|
+
$.auto_view_directive,
|
|
16
|
+
$.bind_directive,
|
|
17
|
+
$.cd_directive,
|
|
18
|
+
$.color_directive,
|
|
19
|
+
$.echo_directive,
|
|
20
|
+
$.exec_directive,
|
|
21
|
+
$.finish_directive,
|
|
22
|
+
$.group_directive,
|
|
23
|
+
$.hdr_order_directive,
|
|
24
|
+
$.ifdef_directive,
|
|
25
|
+
$.ifndef_directive,
|
|
26
|
+
$.ignore_directive,
|
|
27
|
+
$.lists_directive,
|
|
28
|
+
$.macro_directive,
|
|
29
|
+
$.mailboxes_directive,
|
|
30
|
+
$.named_mailboxes_directive,
|
|
31
|
+
$.mailto_allow_directive,
|
|
32
|
+
$.mime_lookup_directive,
|
|
33
|
+
$.mono_directive,
|
|
34
|
+
$.my_hdr_directive,
|
|
35
|
+
$.nospam_directive,
|
|
36
|
+
$.push_directive,
|
|
37
|
+
$.reset_directive,
|
|
38
|
+
$.score_directive,
|
|
39
|
+
$.set_directive,
|
|
40
|
+
$.setenv_directive,
|
|
41
|
+
$.sidebar_pin_directive,
|
|
42
|
+
$.sidebar_unpin_directive,
|
|
43
|
+
$.source_directive,
|
|
44
|
+
$.spam_directive,
|
|
45
|
+
$.subjectrx_directive,
|
|
46
|
+
$.subscribe_directive,
|
|
47
|
+
$.toggle_directive,
|
|
48
|
+
$.unalias_directive,
|
|
49
|
+
$.unalternates_directive,
|
|
50
|
+
$.unalternative_order_directive,
|
|
51
|
+
$.unattachments_directive,
|
|
52
|
+
$.unauto_view_directive,
|
|
53
|
+
$.unbind_directive,
|
|
54
|
+
$.uncolor_directive,
|
|
55
|
+
$.ungroup_directive,
|
|
56
|
+
$.unhdr_order_directive,
|
|
57
|
+
$.unhook_directive,
|
|
58
|
+
$.unignore_directive,
|
|
59
|
+
$.unlists_directive,
|
|
60
|
+
$.unmacro_directive,
|
|
61
|
+
$.unmailboxes_directive,
|
|
62
|
+
$.unmailto_allow_directive,
|
|
63
|
+
$.unmime_lookup_directive,
|
|
64
|
+
$.unmono_directive,
|
|
65
|
+
$.unmy_hdr_directive,
|
|
66
|
+
$.unscore_directive,
|
|
67
|
+
$.unset_directive,
|
|
68
|
+
$.unsetenv_directive,
|
|
69
|
+
$.unsubjectrx_directive,
|
|
70
|
+
$.unsubscribe_directive,
|
|
71
|
+
$.account_hook_directive,
|
|
72
|
+
$.charset_hook_directive,
|
|
73
|
+
$.iconv_hook_directive,
|
|
74
|
+
$.crypt_hook_directive,
|
|
75
|
+
$.index_format_hook_directive,
|
|
76
|
+
$.fcc_save_hook_directive,
|
|
77
|
+
$.fcc_hook_directive,
|
|
78
|
+
$.save_hook_directive,
|
|
79
|
+
$.folder_hook_directive,
|
|
80
|
+
$.mbox_hook_directive,
|
|
81
|
+
$.message_hook_directive,
|
|
82
|
+
$.open_hook_directive,
|
|
83
|
+
$.close_hook_directive,
|
|
84
|
+
$.append_hook_directive,
|
|
85
|
+
$.reply_hook_directive,
|
|
86
|
+
$.send_hook_directive,
|
|
87
|
+
$.send2_hook_directive,
|
|
88
|
+
$.timeout_hook_directive,
|
|
89
|
+
$.startup_hook_directive,
|
|
90
|
+
$.shutdown_hook_directive,
|
|
91
|
+
$.subscribe_to_directive,
|
|
92
|
+
$.unsubscribe_from_directive
|
|
93
|
+
),
|
|
94
|
+
|
|
95
|
+
account_hook_directive: ($) =>
|
|
96
|
+
command($, "account-hook", $._string, $._command),
|
|
97
|
+
|
|
98
|
+
group_name: ($) => $._string,
|
|
99
|
+
// TODO: support more `group_name`s
|
|
100
|
+
_group: ($) => seq(alias("-group", $.command_line_option), $.group_name),
|
|
101
|
+
_addresses: ($) => commaSep1($.address),
|
|
102
|
+
alias_directive: ($) =>
|
|
103
|
+
command($, "alias", optional($._group), $.key, $._addresses),
|
|
104
|
+
address: ($) => $._string,
|
|
105
|
+
unalias_directive: ($) =>
|
|
106
|
+
command($, "unalias", optional($._group), choice("*", $.key)),
|
|
107
|
+
key: ($) =>
|
|
108
|
+
repeat1(
|
|
109
|
+
choice(
|
|
110
|
+
seq("<", alias(/[a-zA-Z-]+/, $.key_name), ">"),
|
|
111
|
+
/[^\n\\ ]/,
|
|
112
|
+
alias(/\\./, $.escape)
|
|
113
|
+
)
|
|
114
|
+
),
|
|
115
|
+
|
|
116
|
+
_regexes: ($) => spaceSep1($._regex),
|
|
117
|
+
alternates_directive: ($) =>
|
|
118
|
+
command($, "alternates", optional($._group), $._regexes),
|
|
119
|
+
unalternates_directive: ($) =>
|
|
120
|
+
command($, "unalternates", optional($._group), choice("*", $._regexes)),
|
|
121
|
+
alternative_order_directive: ($) =>
|
|
122
|
+
command($, "alternative_order", $._mimes),
|
|
123
|
+
unalternative_order_directive: ($) =>
|
|
124
|
+
command($, "unalternative_order", choice("*", $._mimes)),
|
|
125
|
+
mime_type: (_) => /[-.a-zA-Z\d]+/,
|
|
126
|
+
mime: ($) =>
|
|
127
|
+
seq($.mime_type, optional(seq("/", alias($.mime_type, $.sub_mime_type)))),
|
|
128
|
+
_mime_types: ($) => spaceSep1($.mime_type),
|
|
129
|
+
_mimes: ($) => spaceSep1($.mime),
|
|
130
|
+
disposition: ($) => $._string,
|
|
131
|
+
attachments_directive: ($) =>
|
|
132
|
+
command(
|
|
133
|
+
$,
|
|
134
|
+
"attachments",
|
|
135
|
+
choice(
|
|
136
|
+
seq(optional(choice("+", "-")), $.disposition, $._mime_types),
|
|
137
|
+
"?"
|
|
138
|
+
)
|
|
139
|
+
),
|
|
140
|
+
unattachments_directive: ($) =>
|
|
141
|
+
command(
|
|
142
|
+
$,
|
|
143
|
+
"unattachments",
|
|
144
|
+
choice(
|
|
145
|
+
seq(optional(choice("+", "-")), $.disposition, $._mime_types),
|
|
146
|
+
"*"
|
|
147
|
+
)
|
|
148
|
+
),
|
|
149
|
+
auto_view_directive: ($) => command($, "auto_view", $._mimes),
|
|
150
|
+
unauto_view_directive: ($) =>
|
|
151
|
+
command($, "unauto_view", choice("*", $._mimes)),
|
|
152
|
+
|
|
153
|
+
map: (_) =>
|
|
154
|
+
choice(
|
|
155
|
+
"alias",
|
|
156
|
+
"attach",
|
|
157
|
+
"browser",
|
|
158
|
+
"compose",
|
|
159
|
+
"editor",
|
|
160
|
+
"generic",
|
|
161
|
+
"index",
|
|
162
|
+
"mix",
|
|
163
|
+
"pager",
|
|
164
|
+
"pgp",
|
|
165
|
+
"postpone",
|
|
166
|
+
"query",
|
|
167
|
+
"smime"
|
|
168
|
+
),
|
|
169
|
+
_maps: ($) => commaSep1($.map),
|
|
170
|
+
function: (_) => /[a-z-]+/,
|
|
171
|
+
_functions: ($) => spaceSep1($.function),
|
|
172
|
+
bind_directive: ($) => command($, "bind", $._maps, $.key, $.function),
|
|
173
|
+
unbind_directive: ($) => command($, "unbind", choice("*", $._maps), $.key),
|
|
174
|
+
|
|
175
|
+
alias: ($) => $._string,
|
|
176
|
+
charset: ($) => $._string,
|
|
177
|
+
charset_hook_directive: ($) =>
|
|
178
|
+
command($, "charset-hook", $.alias, $.charset),
|
|
179
|
+
iconv_hook_directive: ($) => command($, "iconv-hook", $.charset, $.charset),
|
|
180
|
+
|
|
181
|
+
pattern: ($) => $._string,
|
|
182
|
+
object: (_) =>
|
|
183
|
+
choice(
|
|
184
|
+
"attach_headers",
|
|
185
|
+
"attachment",
|
|
186
|
+
"body",
|
|
187
|
+
"bold",
|
|
188
|
+
"error",
|
|
189
|
+
"hdrdefault",
|
|
190
|
+
"header",
|
|
191
|
+
"index",
|
|
192
|
+
"index_author",
|
|
193
|
+
"index_collapsed",
|
|
194
|
+
"index_date",
|
|
195
|
+
"index_flags",
|
|
196
|
+
"index_label",
|
|
197
|
+
"index_number",
|
|
198
|
+
"index_size",
|
|
199
|
+
"index_subject",
|
|
200
|
+
"index_tag",
|
|
201
|
+
"index_tags",
|
|
202
|
+
"indicator",
|
|
203
|
+
"markers",
|
|
204
|
+
"message",
|
|
205
|
+
"normal",
|
|
206
|
+
"progress",
|
|
207
|
+
"prompt",
|
|
208
|
+
/quoted\d*/,
|
|
209
|
+
"search",
|
|
210
|
+
"signature",
|
|
211
|
+
"status",
|
|
212
|
+
"tilde",
|
|
213
|
+
"tree",
|
|
214
|
+
"underline",
|
|
215
|
+
"sidebar_background",
|
|
216
|
+
"sidebar_divider",
|
|
217
|
+
"sidebar_flagged",
|
|
218
|
+
"sidebar_highlight",
|
|
219
|
+
"sidebar_indicator",
|
|
220
|
+
"sidebar_new",
|
|
221
|
+
"sidebar_ordinary",
|
|
222
|
+
"sidebar_spool_file"
|
|
223
|
+
),
|
|
224
|
+
composeobject: (_) =>
|
|
225
|
+
choice(
|
|
226
|
+
"header",
|
|
227
|
+
"security_encrypt",
|
|
228
|
+
"security_sign",
|
|
229
|
+
"security_both",
|
|
230
|
+
"security_none"
|
|
231
|
+
),
|
|
232
|
+
color: (_) =>
|
|
233
|
+
choice(
|
|
234
|
+
"default",
|
|
235
|
+
"black",
|
|
236
|
+
"red",
|
|
237
|
+
"green",
|
|
238
|
+
"yellow",
|
|
239
|
+
"blue",
|
|
240
|
+
"magenta",
|
|
241
|
+
"cyan",
|
|
242
|
+
"white",
|
|
243
|
+
/#\d{6}/,
|
|
244
|
+
/color\d+/
|
|
245
|
+
),
|
|
246
|
+
attribute: (_) =>
|
|
247
|
+
choice("none", "bold", "underline", "reverse", "standout"),
|
|
248
|
+
_attributes: ($) => spaceSep1($.attribute),
|
|
249
|
+
foreground: ($) => $.color,
|
|
250
|
+
background: ($) => $.color,
|
|
251
|
+
color_directive: ($) =>
|
|
252
|
+
command(
|
|
253
|
+
$,
|
|
254
|
+
"color",
|
|
255
|
+
choice(
|
|
256
|
+
seq(
|
|
257
|
+
$.object,
|
|
258
|
+
optional($._attributes),
|
|
259
|
+
$.foreground,
|
|
260
|
+
$.background,
|
|
261
|
+
$._regex
|
|
262
|
+
),
|
|
263
|
+
seq(
|
|
264
|
+
"compose",
|
|
265
|
+
$.composeobject,
|
|
266
|
+
optional($._attributes),
|
|
267
|
+
$.foreground,
|
|
268
|
+
$.background
|
|
269
|
+
)
|
|
270
|
+
)
|
|
271
|
+
),
|
|
272
|
+
uncolor_directive: ($) =>
|
|
273
|
+
command($, "uncolor", $.pattern, choice("*", $.pattern)),
|
|
274
|
+
|
|
275
|
+
keyid: ($) => $._string,
|
|
276
|
+
crypt_hook_directive: ($) => command($, "crypt-hook", $._regex, $.keyid),
|
|
277
|
+
name: ($) => $._string,
|
|
278
|
+
index_format_hook_directive: ($) =>
|
|
279
|
+
command(
|
|
280
|
+
$,
|
|
281
|
+
"index-format-hook",
|
|
282
|
+
$.name,
|
|
283
|
+
optional("!"),
|
|
284
|
+
$.pattern,
|
|
285
|
+
$._string
|
|
286
|
+
),
|
|
287
|
+
|
|
288
|
+
exec_directive: ($) => command($, "exec", $._functions),
|
|
289
|
+
fcc_save_hook_directive: ($) =>
|
|
290
|
+
command($, "fcc-save-hook", $.pattern, $.mailbox),
|
|
291
|
+
fcc_hook_directive: ($) => command($, "fcc-hook", $.pattern, $.mailbox),
|
|
292
|
+
save_hook_directive: ($) => command($, "save-hook", $.pattern, $.mailbox),
|
|
293
|
+
folder_hook_directive: ($) =>
|
|
294
|
+
command(
|
|
295
|
+
$,
|
|
296
|
+
"folder-hook",
|
|
297
|
+
optional(alias("-noregex", $.command_line_option)),
|
|
298
|
+
$._regex,
|
|
299
|
+
$._command
|
|
300
|
+
),
|
|
301
|
+
|
|
302
|
+
_rx_addr: ($) =>
|
|
303
|
+
choice(
|
|
304
|
+
seq(alias("-rx", $.command_line_option), $._regexes),
|
|
305
|
+
seq(alias("-addr", $.command_line_option), $._addresses)
|
|
306
|
+
),
|
|
307
|
+
group_directive: ($) => command($, "group", optional($._group), $._rx_addr),
|
|
308
|
+
ungroup_directive: ($) =>
|
|
309
|
+
command($, "ungroup", optional($._group), choice("*", $._rx_addr)),
|
|
310
|
+
|
|
311
|
+
header: ($) => $._string,
|
|
312
|
+
_headers: ($) => spaceSep1($.header),
|
|
313
|
+
hdr_order_directive: ($) => command($, "hdr_order", $._headers),
|
|
314
|
+
unhdr_order_directive: ($) =>
|
|
315
|
+
command($, "unhdr_order", choice("*", $._headers)),
|
|
316
|
+
|
|
317
|
+
symbol: ($) => $._string,
|
|
318
|
+
ifdef_directive: ($) => command($, "ifdef", $.symbol, $._command),
|
|
319
|
+
ifndef_directive: ($) => command($, "ifndef", $.symbol, $._command),
|
|
320
|
+
finish_directive: ($) => command($, "finish"),
|
|
321
|
+
|
|
322
|
+
_strings: ($) => spaceSep1($._string),
|
|
323
|
+
ignore_directive: ($) => command($, "ignore", $._strings),
|
|
324
|
+
unignore_directive: ($) => command($, "unignore", choice("*", $._strings)),
|
|
325
|
+
|
|
326
|
+
lists_directive: ($) => command($, "lists", $._group, $._regexes),
|
|
327
|
+
unlists_directive: ($) =>
|
|
328
|
+
command($, "unlists", $._group, choice("*", $._regexes)),
|
|
329
|
+
subscribe_directive: ($) => command($, "subscribe", $._group, $._regexes),
|
|
330
|
+
unsubscribe_directive: ($) =>
|
|
331
|
+
command($, "unsubscribe", $._group, choice("*", $._regexes)),
|
|
332
|
+
|
|
333
|
+
sequence: ($) => $._string,
|
|
334
|
+
macro_directive: ($) => command($, "macro", $._maps, $.key, $.sequence),
|
|
335
|
+
unmacro_directive: ($) =>
|
|
336
|
+
command($, "unmacro", choice("*", $._maps), $.key),
|
|
337
|
+
|
|
338
|
+
mailbox: ($) => $._string,
|
|
339
|
+
_mailboxes: ($) => spaceSep1($.mailbox),
|
|
340
|
+
description: ($) => $._string,
|
|
341
|
+
mailboxes_directive: ($) => command($, "mailboxes", $._mailboxes),
|
|
342
|
+
named_mailboxes_directive: ($) =>
|
|
343
|
+
command($, "named-mailboxes", spaceSep1(seq($.description, $.mailbox))),
|
|
344
|
+
unmailboxes_directive: ($) =>
|
|
345
|
+
command($, "unmailboxes", choice("*", $._mailboxes)),
|
|
346
|
+
|
|
347
|
+
header_field: ($) => $._string,
|
|
348
|
+
_header_fields: ($) => spaceSep1($.header_field),
|
|
349
|
+
mailto_allow_directive: ($) =>
|
|
350
|
+
command($, "mailto_allow", choice("*", $._header_fields)),
|
|
351
|
+
unmailto_allow_directive: ($) =>
|
|
352
|
+
command($, "unmailto_allow", choice("*", $._header_fields)),
|
|
353
|
+
|
|
354
|
+
message: ($) => $._string,
|
|
355
|
+
echo_directive: ($) => command($, "echo", $.message),
|
|
356
|
+
directory: ($) => $._string,
|
|
357
|
+
cd_directive: ($) => command($, "cd", $.directory),
|
|
358
|
+
|
|
359
|
+
mbox_hook_directive: ($) =>
|
|
360
|
+
command($, "mbox-hook", optional("-noregex"), $._regex, $.mailbox),
|
|
361
|
+
message_hook_directive: ($) =>
|
|
362
|
+
command($, "message-hook", $.pattern, $._command),
|
|
363
|
+
|
|
364
|
+
mime_lookup_directive: ($) => command($, "mime_lookup", $._mimes),
|
|
365
|
+
unmime_lookup_directive: ($) =>
|
|
366
|
+
command($, "unmime_lookup", choice("*", $._mimes)),
|
|
367
|
+
mono_directive: ($) =>
|
|
368
|
+
command($, "mono", choice($.object, $.pattern), $.attribute, $._regex),
|
|
369
|
+
unmono_directive: ($) =>
|
|
370
|
+
command($, "unmono", $.pattern, choice("*", $.pattern)),
|
|
371
|
+
my_hdr_directive: ($) => command($, "my_hdr", $._string),
|
|
372
|
+
unmy_hdr_directive: ($) =>
|
|
373
|
+
command($, "unmy_hdr", choice("*", $.header_field)),
|
|
374
|
+
|
|
375
|
+
shell_command: ($) => $._string,
|
|
376
|
+
open_hook_directive: ($) =>
|
|
377
|
+
command($, "open-hook", $._regex, $.shell_command),
|
|
378
|
+
close_hook_directive: ($) =>
|
|
379
|
+
command($, "close-hook", $._regex, $.shell_command),
|
|
380
|
+
append_hook_directive: ($) =>
|
|
381
|
+
command($, "append-hook", $._regex, $.shell_command),
|
|
382
|
+
|
|
383
|
+
push_directive: ($) => command($, "push", $._string),
|
|
384
|
+
|
|
385
|
+
reply_hook_directive: ($) =>
|
|
386
|
+
command($, "reply-hook", $.pattern, $._command),
|
|
387
|
+
send_hook_directive: ($) => command($, "send-hook", $.pattern, $._command),
|
|
388
|
+
send2_hook_directive: ($) =>
|
|
389
|
+
command($, "send2-hook", $.pattern, $._command),
|
|
390
|
+
|
|
391
|
+
format: ($) => $._string,
|
|
392
|
+
spam_directive: ($) => command($, "spam", $._regex, $.format),
|
|
393
|
+
nospam_directive: ($) => command($, "nospam", choice("*", $._regex)),
|
|
394
|
+
replacement: ($) => $._string,
|
|
395
|
+
subjectrx_directive: ($) =>
|
|
396
|
+
command($, "subjectrx", $._regex, $.replacement),
|
|
397
|
+
unsubjectrx_directive: ($) =>
|
|
398
|
+
command($, "unsubjectrx", choice("*", $._regex)),
|
|
399
|
+
uri: ($) => $._string,
|
|
400
|
+
subscribe_to_directive: ($) => command($, "subscribe-to", $.uri),
|
|
401
|
+
unsubscribe_from_directive: ($) => command($, "unsubscribe-from", $.uri),
|
|
402
|
+
|
|
403
|
+
timeout_hook_directive: ($) => command($, "timeout-hook", $._command),
|
|
404
|
+
startup_hook_directive: ($) => command($, "startup-hook", $._command),
|
|
405
|
+
shutdown_hook_directive: ($) => command($, "shutdown-hook", $._command),
|
|
406
|
+
|
|
407
|
+
hook_type: (_) =>
|
|
408
|
+
choice(
|
|
409
|
+
"account-hook",
|
|
410
|
+
"charset-hook",
|
|
411
|
+
"iconv-hook",
|
|
412
|
+
"crypt-hook",
|
|
413
|
+
"fcc-hook",
|
|
414
|
+
"save-hook",
|
|
415
|
+
"folder-hook",
|
|
416
|
+
"mbox-hook",
|
|
417
|
+
"message-hook",
|
|
418
|
+
"open-hook",
|
|
419
|
+
"close-hook",
|
|
420
|
+
"append-hook",
|
|
421
|
+
"reply-hook",
|
|
422
|
+
"send-hook",
|
|
423
|
+
"send2-hook",
|
|
424
|
+
"timeout-hook",
|
|
425
|
+
"startup-hook",
|
|
426
|
+
"shutdown-hook"
|
|
427
|
+
),
|
|
428
|
+
unhook_directive: ($) => command($, "unhook", choice("*", $.hook_type)),
|
|
429
|
+
|
|
430
|
+
set_directive: ($) =>
|
|
431
|
+
command(
|
|
432
|
+
$,
|
|
433
|
+
"set",
|
|
434
|
+
choice(
|
|
435
|
+
seq(
|
|
436
|
+
$.option,
|
|
437
|
+
optional(" "),
|
|
438
|
+
choice("+=", "-=", "="),
|
|
439
|
+
optional(" "),
|
|
440
|
+
choice($.int, $.quadoption, $._string)
|
|
441
|
+
),
|
|
442
|
+
$._options2
|
|
443
|
+
)
|
|
444
|
+
),
|
|
445
|
+
_options2: ($) => spaceSep1(seq(optional(choice("&", "?")), $.option)),
|
|
446
|
+
_options: ($) => spaceSep1($.option),
|
|
447
|
+
unset_directive: ($) => command($, "unset", $._options),
|
|
448
|
+
reset_directive: ($) => command($, "reset", $._options),
|
|
449
|
+
toggle_directive: ($) => command($, "toggle", $._options),
|
|
450
|
+
|
|
451
|
+
setenv_directive: ($) =>
|
|
452
|
+
command(
|
|
453
|
+
$,
|
|
454
|
+
"setenv",
|
|
455
|
+
choice(seq("?", $.option), seq($.option, alias(/\S+/, $.value)))
|
|
456
|
+
),
|
|
457
|
+
unsetenv_directive: ($) => command($, "unsetenv", $.option),
|
|
458
|
+
sidebar_pin_directive: ($) => command($, "sidebar_pin", $._mailboxes),
|
|
459
|
+
sidebar_unpin_directive: ($) =>
|
|
460
|
+
command($, "sidebar_unpin", choice("*", $._mailboxes)),
|
|
461
|
+
score_directive: ($) => command($, "score", $.pattern, $.int),
|
|
462
|
+
unscore_directive: ($) => command($, "unscore", choice("*", $.pattern)),
|
|
463
|
+
|
|
464
|
+
option: (_) => /[a-z_\d]+/,
|
|
465
|
+
|
|
466
|
+
quadoption: (_) => choice("yes", "no", "ask-yes", "ask-no"),
|
|
467
|
+
int: (_) => /-?\d+/,
|
|
468
|
+
_string: ($) =>
|
|
469
|
+
choice(
|
|
470
|
+
quoted_string("'", $.string),
|
|
471
|
+
quoted_string('"', $.shell),
|
|
472
|
+
quoted_string("`", $.shell),
|
|
473
|
+
alias($._word, $.shell),
|
|
474
|
+
"\n"
|
|
475
|
+
),
|
|
476
|
+
_regex: ($) =>
|
|
477
|
+
choice(
|
|
478
|
+
quoted_string("'", $.regex),
|
|
479
|
+
quoted_string('"', $.regex),
|
|
480
|
+
quoted_string("`", $.shell),
|
|
481
|
+
alias($._word, $.regex),
|
|
482
|
+
"\n"
|
|
483
|
+
),
|
|
484
|
+
_word: (_) => /(\\\r?\n|[^"'`\s])(\S|\\\s)*/,
|
|
485
|
+
|
|
486
|
+
source_directive: ($) => command($, "source", alias($._string, $.path)),
|
|
487
|
+
|
|
488
|
+
comment: (_) => /#[^\n]*/,
|
|
489
|
+
_eol: (_) => /\r?\n/,
|
|
490
|
+
_space: (_) => prec(-1, repeat1(/[ \t]/)),
|
|
491
|
+
_end: ($) => seq(optional($._space), optional($.comment), $._eol),
|
|
492
|
+
},
|
|
493
|
+
});
|
|
494
|
+
|
|
495
|
+
function command($, cmd, ...args) {
|
|
496
|
+
return seq(alias(cmd, $.command), ...args);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function sep1(rule, separator) {
|
|
500
|
+
return seq(rule, repeat(seq(separator, rule)));
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
function commaSep1(rule) {
|
|
504
|
+
return sep1(rule, ",");
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
function spaceSep1(rule) {
|
|
508
|
+
return sep1(rule, " ");
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
function quoted_string(char, name) {
|
|
512
|
+
return seq(
|
|
513
|
+
char,
|
|
514
|
+
alias(
|
|
515
|
+
field("content", new RegExp("([^" + char + "]|\\\\" + char + ")+")),
|
|
516
|
+
name
|
|
517
|
+
),
|
|
518
|
+
char
|
|
519
|
+
);
|
|
520
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tree-sitter-muttrc",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "muttrc grammar for tree-sitter",
|
|
5
|
+
"main": "bindings/node",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"parsing",
|
|
8
|
+
"incremental"
|
|
9
|
+
],
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"nan": "^2.12.1"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"tree-sitter-cli": "^0.20.8"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"test": "tree-sitter test"
|
|
18
|
+
},
|
|
19
|
+
"tree-sitter": [
|
|
20
|
+
{
|
|
21
|
+
"scope": "source.muttrc",
|
|
22
|
+
"file-types": [
|
|
23
|
+
"muttrc",
|
|
24
|
+
"neomuttrc"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|