-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
67 lines (53 loc) · 1.33 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
function order($, n) {
return [
repeat($._statement),
repeat($.special),
repeat($.region),
repeat($.group),
repeat($.master),
repeat($.global),
].slice(0, n);
};
function scope($, name, n) {
return seq(alias(name, $.header), ...order($, n));
}
module.exports = grammar({
name: "sfz",
extras: $ => [
/\s/,
$.comment,
],
externals: $ => [
$.literal,
],
word: $ => $.invalid_token,
rules: {
document: $ => seq(...order($)),
_statement: $ => choice(
$.define,
$.include,
$.opcode,
),
define: $ => seq("#define", $.variable, $.literal),
include_path: $ => seq('"', token.immediate(/[^"\r\n]+/), token.immediate('"')),
include: $ => seq("#include", $.include_path),
comment: $ => token(choice(
seq("//", /[^\r\n]*/),
seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, "/"),
)),
global: $ => scope($, "<global>", -1),
master: $ => scope($, "<master>", -2),
group: $ => scope($, "<group>", -3),
region: $ => scope($, "<region>", -4),
special: $ => scope($, /<(control|effect|midi|sample|curve)>/, -5),
variable: $ => /\$\w+/,
identifier: $ => /[a-z_0-9]+/,
opcode: $ => seq(
$.identifier,
optional($.variable),
token.immediate("="),
$.literal,
),
invalid_token: $ => /[^=\s]+/,
}
});