Imported Upstream version 1.12.0
[platform/upstream/augeas.git] / lenses / puppetfile.aug
1 (*
2 Module: Puppetfile
3   Parses libarian-puppet's Puppetfile format
4
5 Author: Raphael Pinson <raphael.pinson@camptocamp.com>
6
7 About: Reference
8   See https://github.com/rodjek/librarian-puppet
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    To be documented
15
16 About: Configuration files
17    This lens applies to Puppetfiles.
18
19 About: Examples
20    The <Test_Puppetfile> file contains various examples and tests.
21 *)
22
23 module Puppetfile =
24
25 (* View: comma
26      a comma, optionally preceded or followed by spaces or newlines *)
27 let comma = del /[ \t\n]*,[ \t\n]*/ ", "
28 let comma_nospace = del /[ \t\n]*,/ ","
29
30 let comment_or_eol = Util.eol | Util.comment_eol
31 let quote_to_comment_or_eol = Quote.do_quote (store /[^#\n]*/) . comment_or_eol
32
33 (* View: moduledir
34      The moduledir setting specifies where modules from the Puppetfile will be installed *)
35 let moduledir = [ Util.indent . key "moduledir" . Sep.space
36                 . quote_to_comment_or_eol ]
37
38 (* View: forge
39      a forge entry *)
40 let forge = [ Util.indent . key "forge" . Sep.space
41             . quote_to_comment_or_eol ]
42
43 (* View: metadata
44      a metadata entry *)
45 let metadata = [ Util.indent . key "metadata" . comment_or_eol ]
46
47 (* View: mod
48      a module entry, with optional version and options *)
49 let mod =
50      let mod_name = Quote.do_quote (store ((Rx.word . /[\/-]/)? . Rx.word))
51   in let version = [ label "@version" . Quote.do_quote (store /[^#:\n]+/) . Util.comment_eol? ]
52   in let sto_opt_val = store /[^#"', \t\n][^#"',\n]*[^#"', \t\n]|[^#"', \t\n]/
53   in let opt = [
54                  Util.del_str ":" . key Rx.word
55                  . (del /[ \t]*=>[ \t]*/ " => " . Quote.do_quote_opt sto_opt_val)?
56                ]
57   in let opt_eol = del /([ \t\n]*\n)?/ ""
58   in let opt_space_or_eol = del /[ \t\n]*/ " "
59   in let comma_opt_eol_comment = comma_nospace . (opt_eol . Util.comment_eol)*
60                                . opt_space_or_eol
61   in let opts = Build.opt_list opt comma_opt_eol_comment
62   in [ Util.indent . Util.del_str "mod" . seq "mod" . Sep.space . mod_name
63      . (comma_opt_eol_comment . version)?
64      . (comma_opt_eol_comment . opts . Util.comment_eol?)?
65      . Util.eol ]
66
67 (* View: lns
68      the Puppetfile lens *)
69 let lns = (Util.empty | Util.comment | forge | metadata | mod | moduledir )*