-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
94 lines (75 loc) · 1.55 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/**
* @file Java properties grammar for tree-sitter
* @author ObserverOfTime
* @license MIT
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: 'properties',
extras: _ => [],
externals: $ => [
$._eof
],
rules: {
file: $ => repeat(seq(
optional($._space),
optional(choice(
$.property,
$.comment
)),
choice($._eol, $._eof)
)),
property: $ => seq(
$.key,
optional($._space),
optional(choice('=', ':')),
optional($._space),
optional($.value)
),
key: $ => prec.right(
repeat1(
choice(
'.',
$._char,
$.escape,
$._index
)
)
),
_index: $ => seq(
'[', alias(repeat($._char), $.index), ']'
),
value: $ => repeat1(choice(
$._char,
$.escape,
$.substitution,
$._linebreak
)),
substitution: $ => seq(
'${',
repeat1(choice(
$.key,
$.substitution
)),
optional(choice(
$._default,
$._secret
)),
'}'
),
_default: $ => seq(':', field('default', $._content)),
_secret: $ => seq('::', alias($._content, $.secret)),
_content: $ => repeat1(
choice($._char, $.escape, $.substitution)
),
_linebreak: $ => seq('\\', $._eol),
escape: _ => choice(
/\\[^\r\n]/, /\\u[0-9a-fA-F]{4}/
),
comment: _ => /[#!].*/,
_space: _ => /[ \t\f]/,
_char: _ => prec(-1, /./),
_eol: _ => /[\r\n]|\r\n/
}
});