Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / aliases.aug
1 (*
2 Module: Aliases
3   Parses /etc/aliases
4
5 Author: David Lutterkort <lutter@redhat.com>
6
7 About: Reference
8   This lens tries to keep as close as possible to `man 5 aliases` where possible.
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    See <lns>.
15
16 About: Configuration files
17    This lens applies to /etc/aliases.
18
19 About: Examples
20    The <Test_Aliases> file contains various examples and tests.
21 *)
22
23 module Aliases =
24    autoload xfm
25
26    (************************************************************************
27     * Group:                 USEFUL PRIMITIVES
28     *************************************************************************)
29
30    (* Group: basic tokens *)
31
32    (* Variable: word *)
33    let word = /[^|", \t\n]+/
34    (* Variable: name *)
35    let name = /([^ \t\n#:|@]+|"[^"|\n]*")/ (* " make emacs calm down *)
36
37    (* Variable: command
38     * a command can contain spaces, if enclosed in double quotes, the case
39     * without spaces is taken care with <word>
40     *)
41    let command = /(\|([^", \t\n]+|"[^"\n]+"))|("\|[^"\n]+")/
42
43    (* Group: Comments and empty lines *)
44
45    (* View: eol *)
46    let eol   = Util.eol
47    (* View: comment *)
48    let comment = Util.comment
49    (* View: empty *)
50    let empty   = Util.empty
51
52    (* Group: separators *)
53    (* View: colon
54     * Separation between the alias and it's destinations
55     *)
56    let colon = del /[ \t]*:[ \t]*/ ":\t"
57    (* View: comma
58     * Separation between multiple destinations
59     *)
60    let comma = del /[ \t]*,[ \t]*(\n[ \t]+)?/ ", "
61
62    (* Group: alias *)
63
64    (* View: destination
65     * Can be either a word (no spaces included) or a command with spaces
66     *)
67    let destination = ( word | command )
68
69    (* View: value_list
70     * List of destinations
71     *)
72    let value_list = Build.opt_list ([ label "value" . store destination]) comma
73
74    (* View: alias
75     * a name with one or more destinations
76     *)
77    let alias = [ seq "alias" .
78                     [ label "name" . store name ] . colon .
79                     value_list
80                 ] . eol
81
82   (* View: lns *)
83   let lns = (comment | empty | alias)*
84
85   let xfm = transform lns (incl "/etc/aliases")
86
87 (* Local Variables: *)
88 (* mode: caml *)
89 (* End: *)