3 Generic module providing useful primitives
5 Author: David Lutterkort
8 This file is licensed under the LGPLv2+, like the rest of Augeas.
17 Delete a string and default to it
20 s:string - the string to delete and default to
22 let del_str (s:string) = del s s
26 Delete mandatory whitespace
28 let del_ws = del /[ \t]+/
32 Delete mandatory whitespace, default to single space
34 let del_ws_spc = del_ws " "
38 Delete mandatory whitespace, default to single tab
40 let del_ws_tab = del_ws "\t"
45 Delete optional whitespace
47 let del_opt_ws = del /[ \t]*/
52 Delete end of line, including optional trailing whitespace
54 let eol = del /[ \t]*\n/ "\n"
58 Delete indentation, including leading whitespace
60 let indent = del /[ \t]*/ ""
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
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 ]
77 Map comments into "#comment" nodes
79 let comment = comment_generic /[ \t]*#[ \t]*/ "# "
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"
97 [ label "#mcomment" . del /[ \t]*\/\*[ \t\n]*/ "/*\n"
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" ]
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 *)
120 empty_generic /[ \t]*((\/\/)|(\/\*[ \t]*\*\/))?[ \t]*/
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 ] ) *
134 Exclusion for files that are commonly not wanted/needed
136 let stdexcl = (excl "*~") .
139 (excl "*.dpkg-old") .
140 (excl "*.dpkg-new") .
141 (excl "*.dpkg-bak") .
142 (excl "*.dpkg-dist") .
146 (* Local Variables: *)