Add LICENSE.BSD-3-Clause file
[platform/upstream/libxkbcommon.git] / doc / rules-format.md
1 The rules file {#rule-file-format}
2 ==============
3
4 The purpose of the rules file is to map between configuration values
5 that are easy for a user to specify and understand, and the
6 configuration values xkbcomp uses and understands.
7
8 xkbcomp uses the `xkb_component_names` struct, which maps directly to
9 include statements of the appropriate sections, called for short
10 [KcCGST](@ref KcCGST-intro) (see the [XKB
11 introduction](doc/introduction-to-xkb.md);
12 'G' stands for "geometry", which is not supported). These are not
13 really intuitive or straight-forward for the uninitiated.
14
15 Instead, the user passes in a `xkb_rule_names` struct, which consists
16 of the name of a rules file (in Linux this is usually "evdev"), a
17 keyboard model (e.g. "pc105"), a set of layouts (which will end up
18 in different groups, e.g. "us,fr"), variants (used to alter/augment
19 the respective layout, e.g. "intl,dvorak"), and a set of options
20 (used to tweak some general behavior of the keyboard, e.g.
21 "ctrl:nocaps,compose:menu" to make the Caps Lock key act like Ctrl
22 and the Menu key like Compose). We call these
23 [RMLVO](@ref RMLVO-intro).
24
25 Format of the file
26 ------------------
27 The file consists of rule sets, each consisting of rules (one per
28 line), which match the MLVO values on the left hand side, and, if
29 the values match to the values the user passed in, results in the
30 values on the right hand side being added to the resulting KcCGST.
31 Since some values are related and repeated often, it is possible
32 to group them together and refer to them by a group name in the
33 rules.
34
35 Along with matching values by simple string equality, and for
36 membership in a group defined previously, rules may also contain
37 "wildcard" values - "*" - which always match. These usually appear
38 near the end.
39
40 Grammar
41 -------
42 (It might be helpful to look at a file like rules/evdev along with
43 this grammar. Comments, whitespace, etc. are not shown.)
44
45 ```
46 File         ::= { "!" (Include | Group | RuleSet) }
47
48 Include      ::= "include" <ident>
49
50 Group        ::= GroupName "=" { GroupElement } "\n"
51 GroupName    ::= "$"<ident>
52 GroupElement ::= <ident>
53
54 RuleSet      ::= Mapping { Rule }
55
56 Mapping      ::= { Mlvo } "=" { Kccgst } "\n"
57 Mlvo         ::= "model" | "option" | ("layout" | "variant") [ Index ]
58 Index        ::= "[" 1..XKB_NUM_GROUPS "]"
59 Kccgst       ::= "keycodes" | "symbols" | "types" | "compat" | "geometry"
60
61 Rule         ::= { MlvoValue } "=" { KccgstValue } "\n"
62 MlvoValue    ::= "*" | GroupName | <ident>
63 KccgstValue  ::= <ident>
64 ```
65
66 Notes:
67
68 - Include processes the rules in the file path specified in the ident,
69   in order. %-expansion is performed, as follows:
70
71 ```
72   %%:
73     A literal %.
74
75   %H:
76     The value of the HOME environment variable.
77
78   %E:
79     The extra lookup path for system-wide XKB data (usually /etc/xkb/rules).
80
81   %S:
82     The system-installed rules directory (usually /usr/share/X11/xkb/rules).
83 ```
84
85 - The order of values in a Rule must be the same as the Mapping it
86   follows. The mapping line determines the meaning of the values in
87   the rules which follow in the RuleSet.
88
89 - If a Rule is matched, %-expansion is performed on the KccgstValue,
90   as follows:
91
92 ```
93   %m, %l, %v:
94      The model, layout or variant, if only one was given (e.g.
95      %l for "us,il" is invalid).
96
97   %l[1], %v[1]:
98      Layout or variant for the specified group Index, if more than
99      one was given (e.g. %l[1] for "us" is invalid).
100
101   %+m, %+l, %+v, %+l[1], %+v[1]
102      As above, but prefixed with '+'. Similarly, '|', '-', '_' may be
103      used instead of '+'.
104
105   %(m), %(l), %(l[1]), %(v), %(v[1]):
106      As above, but prefixed by '(' and suffixed by ')'.
107 ```
108
109   In case the expansion is invalid, as described above, it is
110   skipped (the rest of the string is still processed); this includes
111   the prefix and suffix (that's why you shouldn't use e.g. "(%v[1])").