/usr/share/augeas/lenses/dist/inifile.aug is in augeas-lenses 0.10.0-0ubuntu4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 | (*
Module: IniFile
Generic module to create INI files lenses
Author: Raphael Pinson <raphink@gmail.com>
About: License
This file is licensed under the LGPLv2+, like the rest of Augeas.
About: TODO
Things to add in the future
- Support double quotes in value
About: Lens usage
This lens is made to provide generic primitives to construct INI File lenses.
See <Puppet>, <PHP>, <MySQL> or <Dput> for examples of real life lenses using it.
About: Examples
The <Test_IniFile> file contains various examples and tests.
*)
module IniFile =
(************************************************************************
* Group: USEFUL PRIMITIVES
*************************************************************************)
(* Group: Internal primitives *)
(*
Variable: eol
End of line, inherited from <Util.eol>
*)
let eol = Util.eol
(*
View: empty
Empty line, an <eol> subnode
*)
let empty = [ eol ]
(* Group: Separators *)
(*
Variable: sep
Generic separator
Parameters:
pat:regexp - the pattern to delete
default:string - the default string to use
*)
let sep (pat:regexp) (default:string)
= Sep.opt_space . del pat default
(*
Variable: sep_re
The default regexp for a separator
*)
let sep_re = /[=:]/
(*
Variable: sep_default
The default separator value
*)
let sep_default = "="
(* Group: Stores *)
(*
Variable: sto_to_eol
Store until end of line
*)
let sto_to_eol = Sep.opt_space . store Rx.space_in
(*
Variable: to_comment_re
Regex until comment
*)
let to_comment_re = /[^;# \t\n][^;#\n]*[^;# \t\n]|[^;# \t\n]/
(*
Variable: sto_to_comment
Store until comment
*)
let sto_to_comment = Sep.opt_space . store to_comment_re
let sto_multiline = Sep.opt_space
. store (to_comment_re
. (/[ \t]*\n/ . Rx.space . to_comment_re)*)
(* Group: Define comment and defaults *)
(*
View: comment
Map comments into "#comment" nodes
Parameters:
pat:regexp - pattern to delete before commented data
default:string - default pattern before commented data
Sample Usage:
(start code)
let comment = IniFile.comment "#" "#"
let comment = IniFile.comment IniFile.comment_re IniFile.comment_default
(end code)
*)
let comment (pat:regexp) (default:string)
= [ label "#comment" . sep pat default
. sto_to_eol? . eol ]
(*
Variable: comment_re
Default regexp for <comment> pattern
*)
let comment_re = /[;#]/
(*
Variable: comment_default
Default value for <comment> pattern
*)
let comment_default = ";"
(************************************************************************
* Group: ENTRY
*************************************************************************)
(* Group: entry includes comments *)
(*
View: entry
Generic INI File entry
Parameters:
kw:regexp - keyword regexp for the label
sep:lens - lens to use as key/value separator
comment:lens - lens to use as comment
Sample Usage:
> let entry = IniFile.entry setting sep comment
*)
let entry (kw:regexp) (sep:lens) (comment:lens)
= [ key kw . sep . sto_to_comment? . (comment|eol) ] | comment
let entry_multiline (kw:regexp) (sep:lens) (comment:lens)
= [ key kw . sep . sto_multiline? . (comment|eol) ] | comment
(*
View: indented_entry
Generic INI File entry that might be indented with an arbitrary
amount of whitespace
Parameters:
kw:regexp - keyword regexp for the label
sep:lens - lens to use as key/value separator
comment:lens - lens to use as comment
Sample Usage:
> let entry = IniFile.indented_entry setting sep comment
*)
let indented_entry (kw:regexp) (sep:lens) (comment:lens)
= [ Util.del_opt_ws "" .
key kw . sep . sto_to_comment? .
(comment|eol)
]
| comment
(*
Variable: entry_re
Default regexp for <entry> keyword
*)
let entry_re = ( /[A-Za-z][A-Za-z0-9._-]+/ )
(************************************************************************
* Group: RECORD
*************************************************************************)
(* Group: Title definition *)
(*
View: title
Title for <record>. This maps the title of a record as a node in the abstract tree.
Parameters:
kw:regexp - keyword regexp for the label
Sample Usage:
> let title = IniFile.title IniFile.record_re
*)
let title (kw:regexp)
= Util.del_str "[" . key kw
. Util.del_str "]". eol
(*
View: indented_title
Title for <record>. This maps the title of a record as a node in the abstract tree. The title may be indented with arbitrary amounts of whitespace
Parameters:
kw:regexp - keyword regexp for the label
Sample Usage:
> let title = IniFile.title IniFile.record_re
*)
let indented_title (kw:regexp)
= Util.indent . title kw
(*
View: title_label
Title for <record>. This maps the title of a record as a value in the abstract tree.
Parameters:
name:string - name for the title label
kw:regexp - keyword regexp for the label
Sample Usage:
> let title = IniFile.title_label "target" IniFile.record_label_re
*)
let title_label (name:string) (kw:regexp)
= label name
. Util.del_str "[" . store kw
. Util.del_str "]". eol
(*
View: indented_title_label
Title for <record>. This maps the title of a record as a value in the abstract tree. The title may be indented with arbitrary amounts of whitespace
Parameters:
name:string - name for the title label
kw:regexp - keyword regexp for the label
Sample Usage:
> let title = IniFile.title_label "target" IniFile.record_label_re
*)
let indented_title_label (name:string) (kw:regexp)
= Util.indent . title_label name kw
(*
Variable: record_re
Default regexp for <title> keyword pattern
*)
let record_re = ( /[^]\n\/]+/ - /#comment/ )
(*
Variable: record_label_re
Default regexp for <title_label> keyword pattern
*)
let record_label_re = /[^]\n]+/
(* Group: Record definition *)
(*
View: record_noempty
INI File Record with no empty lines allowed.
Parameters:
title:lens - lens to use for title. Use either <title> or <title_label>.
entry:lens - lens to use for entries in the record. See <entry>.
*)
let record_noempty (title:lens) (entry:lens)
= [ title
. entry* ]
(*
View: record
Generic INI File record
Parameters:
title:lens - lens to use for title. Use either <title> or <title_label>.
entry:lens - lens to use for entries in the record. See <entry>.
Sample Usage:
> let record = IniFile.record title entry
*)
let record (title:lens) (entry:lens)
= record_noempty title ( entry | empty )
(************************************************************************
* Group: LENS
*************************************************************************)
(*
Group: Lens definition
View: lns_noempty
Generic INI File lens with no empty lines
Parameters:
record:lens - record lens to use. See <record_noempty>.
comment:lens - comment lens to use. See <comment>.
Sample Usage:
> let lns = IniFile.lns_noempty record comment
*)
let lns_noempty (record:lens) (comment:lens)
= comment* . record*
(*
View: lns
Generic INI File lens
Parameters:
record:lens - record lens to use. See <record>.
comment:lens - comment lens to use. See <comment>.
Sample Usage:
> let lns = IniFile.lns record comment
*)
let lns (record:lens) (comment:lens)
= lns_noempty record (comment|empty)
|