[augeas-devel] ConfigObj: working lens seeking tips/improvements
Yclept Nemo
orbisvicis at gmail.com
Tue Oct 27 03:30:11 UTC 2015
Here's a working ConfigObj lens. It is finished but I'm looking for
possible improvements. There are some annoyances:
* union branches are exclusive yet augeas won't fill in derived nodes.
Nodes "type" or "commented" must both be provided.
* union branches are unordered (being exclusive) yet the child nodes
must be filled in a specific order: "commented" -> "type" -> ".comment"
>> 1 module ConfigObj =
>> 2 let spaces = del /[ \t]*/ " "
>> 3 let option = key /[a-z]([a-z_]*[a-z])?/
>> 4 let option_pad = option . spaces
>> 5 let value_bool = store /(true|false)/ . [ label "type"
. value "bool" ]
>> 6 let value_int = store /(0|[+-]?[1-9][0-9]*)/ . [ label
"type" . value "int" ]
>> 7 let value_decimal = store (/(0|[+-]?[1-9][0-9]*)\.[0-9]+/
- /[+-]0\.0+/) . [ label "type" . value "decimal" ]
>> 8 let value_hex_int = store /0x[0-9a-fA-F]+/ . [ label
"type" . value "hex int" ]
>> 9 let value_any_simple = value_bool | value_int | value_decimal
| value_hex_int
>> 10 let value_qstring = (del "\"" "\"") . (store
/([^\n\"]*([\].)*)*/) . (del "\"" "\"") . [ label "type" . value "quoted
string" ]
>> 11 let value_ustring = store (/[^ \t\n"#]+/ - lens_ctype
value_any_simple) . [ label "type" . value "unquoted string" ]
>> 12 let value_none = [ label "type" . value "none" ]
>> 13 let value_any = value_any_simple | value_qstring |
value_ustring
>> 14 let value_any_pad = ( value_any . spaces ) | value_none
>> 15 let sep_assign = del /=[ \t]*/ "= "
>> 16 let sep_comment = del /#[ \t]*/ "# "
>> 17 let comment_label = label ".comment"
>> 18 let record_commented = [ sep_comment . label "commented" .
value "true" ] | [ label "commented" . value "false" ]
>> 19 let record_comment = [ comment_label . del /#/ "#" . store
/.*/ ]
>> 20 let record_simple = option_pad . sep_assign .
value_any_pad . record_comment?
>> 21 let record = [ record_commented . record_simple ]
>> 22 let comment = [ comment_label . del /#/ "#" . store
(/.*/ - (/[ \t]*/ . lens_ctype record_simple)) ]
>> 23 let entry = del /[ \t]*/ "" . ( record | comment )
. del /\n/ "\n"
>> 24 let empty = [ del /[ \t]*\n/ "\n" ]
>> 25 let line = empty | entry
>> 26 let lns = line *
Sincerely,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listman.redhat.com/archives/augeas-devel/attachments/20151026/2e3ddc6e/attachment.htm>
More information about the augeas-devel
mailing list