-
Notifications
You must be signed in to change notification settings - Fork 11
/
grammar.js
45 lines (38 loc) · 849 Bytes
/
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
module.exports = grammar({
name: 'ini',
extras: $ => [
$.comment,
$._blank,
/[\t ]/
],
rules: {
document: $ => seq(
repeat($._blank), // Eat blank lines at top of file.
repeat($.section),
),
// Section has:
// - a title
// - zero or more settings (name=value pairs)
// - comments (optional)
section: $ => prec.left(seq(
$.section_name,
repeat(seq(
$.setting,
)),
)),
section_name: $ => seq(
'[',
alias(/[^\[\]]+/, $.text),
']',
/\r?\n/,
),
setting: $ => seq(
alias(/[^;#=\s\[]+( *[^;#=\s\[])*/, $.setting_name),
'=',
optional(alias(/.+/, $.setting_value)),
/\r?\n/,
),
comment: $ => seq(/[;#]/, alias(/[^\r\n]*/, $.text), /\r?\n/),
_blank: () => field('blank', /\r?\n/),
}
});