ovirt-node 2.2.0 release
[ovirt-node.git] / augeas / util.aug
blobcef5b155195b49f7aeba91540f7d46c19ed54713
1 (*
2 Module: Util
3   Generic module providing useful primitives
5 Author: David Lutterkort
7 About: License
8   This file is licensed under the LGPLv2+, like the rest of Augeas.
9 *)
12 module Util =
16 Variable: del_str
17   Delete a string and default to it
19   Parameters:
20      s:string - the string to delete and default to
22   let del_str (s:string) = del s s
25 Variable: del_ws
26   Delete mandatory whitespace
28   let del_ws = del /[ \t]+/
31 Variable: del_ws_spc
32   Delete mandatory whitespace, default to single space
34   let del_ws_spc = del_ws " "
37 Variable: del_ws_tab
38   Delete mandatory whitespace, default to single tab
40   let del_ws_tab = del_ws "\t"
44 Variable: del_opt_ws
45   Delete optional whitespace
47   let del_opt_ws = del /[ \t]*/
51 Variable: eol
52   Delete end of line, including optional trailing whitespace
54   let eol = del /[ \t]*\n/ "\n"
57 Variable: indent
58   Delete indentation, including leading whitespace
60   let indent = del /[ \t]*/ ""
62 (* Group: Comment
63      This is a general definition of comment
64      It allows indentation for comments, removes the leading and trailing spaces
65      of comments and stores them in nodes, except for empty comments which are
66      ignored together with empty lines
68 View: comment_generic
69   Map comments and set default comment sign
72   let comment_generic (r:regexp) (d:string) =
73     [ label "#comment" . del r d
74         . store /([^ \t\n].*[^ \t\n]|[^ \t\n])/ . eol ]
76 (* View: comment
77   Map comments into "#comment" nodes
79   let comment = comment_generic /[ \t]*#[ \t]*/ "# "
81 (* View: comment_eol
82   Map eol comments into "#comment" nodes
83   Add a space before # for end of line comments
85   let comment_eol = comment_generic /[ \t]*#[ \t]*/ " # "
87 (* View: comment_or_eol
88     A <comment_eol> or <eol> *)
89  let comment_or_eol = comment_eol | (del /[ \t]*#?\n/ "\n")
91 (* View: comment_multiline
92     A C-style multiline comment *)
93   let comment_multiline =
94      let mline_re = (/[^ \t\n].*[^ \t\n]|[^ \t\n]/ - /.*\*\/.*/) in
95      let mline = [ seq "mline"
96                  . store mline_re ] in
97      [ label "#mcomment" . del /[ \t]*\/\*[ \t\n]*/ "/*\n"
98        . counter "mline"
99        . (mline . (eol . mline)*)
100        . del /[ \t\n]*\*\/[ \t]*\n/ "\n*/\n" ]
102 (* View: comment_c_style
103     A comment line, C-style *)
104   let comment_c_style =
105     comment_generic /[ \t]*\/\/[ \t]*/ "// "
107 (* View: empty_generic
108   A generic definition of <empty>
109   Map empty lines, including empty comments *)
110   let empty_generic (r:regexp) =
111     [ del r "" . del_str "\n" ]
113 (* View: empty
114   Map empty lines, including empty comments *)
115   let empty = empty_generic /[ \t]*#?[ \t]*/
117 (* View: empty_c_style
118   Map empty lines, including C-style empty comment *)
119   let empty_c_style =
120     empty_generic /[ \t]*((\/\/)|(\/\*[ \t]*\*\/))?[ \t]*/
123 (* View: Split *)
124 (* Split (SEP . ELT)* into an array-like tree where each match for ELT *)
125 (* appears in a separate subtree. The labels for the subtrees are      *)
126 (* consecutive numbers, starting at 0                                  *)
127   let split (elt:lens) (sep:lens) =
128     let sym = gensym "split" in
129     counter sym . ( [ seq sym . sep . elt ] ) *
131 (* Group: Exclusions
133 Variable: stdexcl
134   Exclusion for files that are commonly not wanted/needed
136   let stdexcl = (excl "*~") .
137     (excl "*.rpmnew") .
138     (excl "*.rpmsave") .
139     (excl "*.dpkg-old") .
140     (excl "*.dpkg-new") .
141     (excl "*.dpkg-bak") .
142     (excl "*.dpkg-dist") .
143     (excl "*.augsave") .
144     (excl "*.augnew")
146 (* Local Variables: *)
147 (* mode: caml       *)
148 (* End:             *)