-
Notifications
You must be signed in to change notification settings - Fork 37
/
XKBGrammar.g
203 lines (173 loc) · 3.52 KB
/
XKBGrammar.g
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
// XKB Grammar (X.org)
// Written by Simos Xenitellis <[email protected]>, 2008.
// Version 0.8
grammar XKBGrammar;
options
{
language = Python;
output = AST;
}
tokens
{
// Keywords
TOKEN_INCLUDE;
TOKEN_KEY_TYPE;
TOKEN_NAME;
TOKEN_KEY;
TOKEN_TYPE;
TOKEN_MODIFIER_MAP;
TOKEN_SYMBOL;
TOKEN_VIRTUAL_MODIFIERS;
// Tokens for tree.
LAYOUT;
SYMBOLS;
MAPTYPE;
MAPNAME;
MAPOPTIONS;
MAPMATERIAL;
KEYCODE;
KEYCODEX;
VALUE;
STATE;
ELEM_KEYSYMGROUP;
ELEM_KEYSYMS;
ELEM_VIRTUALMODS;
KEYELEMENTS;
OVERRIDE;
OVERLAY;
}
// We cover XKB symbol files that look like
//
// // comments can appear here.
// one of more modifiers "mysymbolsname"
// {
// // comments can appear here.
// include "somename" // comments can also appear here.
// name[somestring] = "sometext";
// key.type[someotherstring] = "someothertext";
// key <someotherstring> { [ somesymbol, someothersymbol, ... uptoEightSymbols ] };
// modifier_map someothertext { somesymbol, someothersymbol, ... uptoEightSymbols };
// // can also have multiples of the above.
// };
//
// // can have several symbol sections as above.
layout
: symbols+ EOF
-> ^(LAYOUT symbols+)
;
symbols
: mapType '{' mapMaterial+ '}' ';'
-> ^(SYMBOLS mapType ^(MAPMATERIAL mapMaterial+))
;
mapType
: MAPOPTS+ DQSTRING
-> ^(MAPTYPE ^(MAPOPTIONS MAPOPTS+) ^(MAPNAME DQSTRING))
;
mapMaterial
: line_include
| line_name ';'!
| line_keytype ';'!
| line_key ';'!
| line_modifier_map ';'!
| line_virtual_modifiers ';'!
;
line_include
: 'include' DQSTRING
-> ^(TOKEN_INCLUDE DQSTRING)
;
line_name
: 'name' ('[' NAME ']')? '=' DQSTRING
-> ^(TOKEN_NAME DQSTRING)
;
line_keytype
: 'key.type' ('[' NAME ']')? '=' DQSTRING
-> ^(TOKEN_KEY_TYPE DQSTRING)
;
line_key
: OVERRIDE? 'key' '<' NAME '>' '{' keyelements (',' keyelements)* '}'
-> ^(TOKEN_KEY OVERRIDE? ^(KEYCODEX NAME) keyelements+)
;
line_modifier_map
: 'modifier_map' STATE '{' keycode (',' keycode)* '}'
-> ^(TOKEN_MODIFIER_MAP STATE keycode+)
;
line_virtual_modifiers
: 'virtual_modifiers' NAME (',' NAME)*
-> ^(TOKEN_VIRTUAL_MODIFIERS NAME+)
;
keycode
: '<' NAME '>' -> ^(KEYCODEX NAME)
| NAME -> ^(KEYCODE NAME)
;
override
: 'override'
;
keyelements
: elem_keysyms
| elem_keysymgroup
| elem_virtualmods
| elem_overlay
;
elem_keysyms
: 'type' ('[' NAME ']')? '=' DQSTRING
-> ^(ELEM_KEYSYMS DQSTRING)
;
elem_keysymgroup
: ('symbols' '[' NAME ']' '=')? '[' keysym+=NAME (',' keysym+=NAME)* ']'
-> ^(ELEM_KEYSYMGROUP ^(VALUE $keysym+ ))
;
elem_virtualmods
: ('virtualMods' '=' NAME)
-> ^(ELEM_VIRTUALMODS NAME)
;
elem_overlay
: NAME '=' keycode
-> ^(OVERLAY NAME keycode)
;
MAPOPTS
: 'default'
| 'hidden'
| 'partial'
| 'alphanumeric_keys'
| 'keypad_keys'
| 'function_keys'
| 'modifier_keys'
| 'alternate_group'
| 'xkb_symbols'
;
STATE
: 'Shift'
| 'Control'
| 'Lock'
| 'Mod1'
| 'Mod2'
| 'Mod3'
| 'Mod4'
| 'Mod5'
;
OVERRIDE
: 'override'
;
NAME
: ( 'a'..'z' | 'A'..'Z' | '_' | '0'..'9' | '+' | '-' )*
;
WS
:
( ' ' | '\r' | '\t' | '\u000C' | '\n')
{ $channel=HIDDEN; }
;
COMMENT
:
'/*' .* '*/' {$channel=HIDDEN;}
;
LINE_COMMENT
:
('//' | '#') ~('\n' | '\r')* '\r'? '\n'
{ $channel=HIDDEN; }
;
/** Match various string types. Note that greedy=false implies '''
* should make us exit loop not continue.
*/
DQSTRING
: '"' (options {greedy=false;}:~('"'))* '"'
;