-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
grammar.js
95 lines (77 loc) · 1.56 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
95
/**
* @file Tree-sitter grammar definition
* @author ObserverOfTime
* @license MIT
*/
/// <reference types="tree-sitter-cli/dsl" />
// @ts-check
module.exports = grammar({
name: 'xcompose',
extras: _ => [],
conflicts: $ => [
[$.result]
],
rules: {
compose: $ => repeat(
seq(
optional($._space),
optional(choice(
$.include,
$.sequence,
$.comment,
)),
/\n/
)
),
include: $ => seq(
'include',
$._space,
'"',
choice(
'%L', seq(
choice('%H', '%S'),
$.text
)
),
'"',
optional($._space)
),
sequence: $ => seq(
repeat1(seq($.event, $._space)),
':',
$._space,
$.result,
optional($._space),
optional($.comment)
),
event: $ => seq(
optional(seq('!', $._space)),
optional(choice(
repeat(seq(
optional(seq('~', $._space)),
$.modifier,
$._space
)),
seq('None', $._space),
)),
'<', $.keysym, '>',
),
result: $ => choice(
$.string,
$.keysym,
seq($.string, $._space, $.keysym)
),
string: $ => seq(
'"', choice($.text, $.octal, $.hex), '"'
),
modifier: _ => token(choice(
'Ctrl', 'Lock', 'Caps', 'Shift', 'Alt', 'Meta'
)),
keysym: _ => /[A-Za-z0-9_]+/,
text: _ => repeat1(/[^"]|\\"/),
octal: _ => /\\[0-9]{1,3}/,
hex: _ => /\\0?x[0-9a-fA-F]{2,4}/,
comment: _ => /#.*/,
_space: _ => /[ \t]+/
}
});