-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgrammar.js
52 lines (39 loc) · 1004 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
47
48
49
50
51
52
const NEWLINE = /\r?\n/
module.exports = grammar({
name: 'dotenv',
extras: $ => [
$.comment,
/\s/
],
rules: {
source_file: $ => repeat(choice(
$.comment,
$.variable
)),
comment: $ => token(seq("#", /.*/)),
variable: $ => seq(
field("name", $.identifier),
"=",
optional(field("value", $.value))
),
interpolated_variable: $ => seq('$', $.identifier),
identifier: $ => /[A-Z][0-9a-zA-Z_]*/,
value: $ => choice(
$.bool,
$.string_interpolated,
$.string_literal,
$.integer,
$.raw_value,
// TODO: More value types
),
bool: $ => choice(
'true',
'false'
),
integer: $ => /\d+/,
string_interpolated: $ => seq('"', repeat($._interpolated_content), '"'),
_interpolated_content: $ => choice(/[^"]/, $.interpolated_variable),
string_literal: $ => seq("'", repeat(/[^']/), "'"),
raw_value: $ => /\w+/
}
})