-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
79 lines (62 loc) · 1.78 KB
/
grammar.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/**
* @file Tree-sitter parser for Brewfile
* @author Nicolas Marien
* @license MIT
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: "brewfile",
rules: {
source_file: ($) => repeat($._line),
_line: ($) =>
choice(
seq($.tap_directive, "\n"),
seq($.brew_directive, "\n"),
seq($.cask_directive, "\n"),
seq($.mas_directive, "\n"),
seq($.vscode_directive, "\n"),
seq($.comment, "\n"),
"\n"
),
tap_directive: ($) =>
seq("tap", optional($.quoted_string), optional($.options)),
brew_directive: ($) =>
seq("brew", optional($.quoted_string), optional($.options)),
cask_directive: ($) =>
seq("cask", optional($.quoted_string), optional($.options)),
mas_directive: ($) =>
seq(
"mas",
optional($.quoted_string),
optional($.app_id),
optional($.options)
),
vscode_directive: ($) =>
seq("vscode", optional($.quoted_string), optional($.options)),
options: ($) => seq(",", choice($.hash_options, $.array_options)),
hash_options: ($) =>
seq("{", repeat(seq($.key_value_pair, optional(","))), "}"),
array_options: ($) =>
seq(
"[",
repeat(seq(choice($.quoted_string, $.number), optional(","))),
"]"
),
key_value_pair: ($) =>
seq(
field("key", $.identifier),
":",
field(
"value",
choice($.quoted_string, $.number, "true", "false", "nil")
)
),
quoted_string: ($) =>
choice(seq('"', /[^"]*/, '"'), seq("'", /[^']*/, "'")),
app_id: ($) => /[0-9]+/,
number: ($) => /[0-9]+/,
identifier: ($) => /[a-zA-Z_][a-zA-Z0-9_]*/,
comment: ($) => seq("#", /.*/),
},
});