-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
41 lines (33 loc) · 903 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
function sep1(rule) {
return seq(rule, repeat(seq(/[ \t]+/, rule)));
}
function sep(rule) {
return optional(sep1(rule));
}
module.exports = grammar({
name: 'bazelrc',
extras: _ => [],
rules: {
source_file: $ => repeat(choice($.comment, $.try_import, $.import, $.command, $._emptyline)),
comment: $ => seq('#', /.*/, $._newline),
_newline: _ => /\r?\n/,
_blank: _ => /[ \t]/,
_emptyline: _ => /[ \t]*\r?\n/,
option: _ => /[^\s]+/,
command: $ => seq(
field("name", $.command_name),
optional(seq(
':',
field("config", $.config_name),
)),
$._blank,
sep($.option),
$._newline,
),
command_name: _ => /[a-z][a-z_\-]+/,
config_name: _ => /[a-z][a-z_\-]+/,
import_path: _ => /[a-z0-9\/\\%\.~_\-]+/i,
try_import: $ => seq('try-import', $._blank, $.import_path, $._newline),
import: $ => seq('import', $._blank, $.import_path, $._newline),
}
});