forked from justinmk/tree-sitter-ini
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
46 lines (39 loc) · 855 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
46
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)
section: $ => prec.left(seq(
$.section_name,
repeat(seq(
$.setting,
)),
)),
section_name: $ => seq(
'[',
alias(/[^\[\]\n]+/, $.text),
']',
'\n',
),
setting: $ => seq(
alias(/[^#=\s\[]+/, $.setting_name),
'=',
alias(/.+/, $.setting_value),
'\n',
),
// setting_name: () => /[^#=\s\[]+/,
// setting_value: () => /[^#\n]+/,
comment: $ => seq('#', alias(/.*/, $.text), '\n'),
_blank: () => field('blank', '\n'),
}
});