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