Dealing with comments

This page intends to list the various ways to deal with comments in Augeas lenses, and the pros and cons of these methods.


This page will list different trees to represent the following file (located as /path/to/file):

field1=value1
# field2=value2
# a standard comment


Note: the examples beneath are experimental attempts by the author of this post. The Augeas development team does not necessarily agree with these choices.


Contents

Pure comments

Ignore comments

The first lenses made for Augeas ignored all comments. Comments were deleted altogether with empty lines.


Tree

/files/path/to/file/field1 = "value1"
(null)
(null)


Example implementation

let comment = [ del /(#.*|[ \t]*)\n/ "\n" ]


Pros and cons


Create comment nodes

Tree

/files/path/to/file/field1 = "value1"
/files/path/to/file/comment[1] = "field2=value2"
/files/path/to/file/comment[2] = "a standard comment"

Example implementation

let comment = [ label "comment" . del /#[ \t]*/ "#" .  store /([^ \t\n][^\n]*)?/ . eol ]
let empty  = [ del /[ \t]*/ "" . eol ]


Pros and cons


Commented values

Create commented flags for nodes

Tree

/files/path/to/file/field1 = "value1"
/files/path/to/file/field2 = "value2"
/files/path/to/file/field2/commented
/files/path/to/file/comment = "a standard comment"

Example implementation

let commented = [ label "commented" . del /#[ \t]*/ "# " ]
let comment = [ label "comment" . del /#[ \t]*/ "# " . store ( /[^ \t\n][^\n]*)/ - /[ \t]*value[ \t]*=[ \t]*[^# \t\n][^#\n]*/ ) . Util.del_str "\n" ]
let record = [ seq "record" . commented? . [ key "value" . del /[ \t]*=[ \t]*/ " = " . store /[^# \t\n][^#\n]*/ ] . Util.del_str "\n" ]


Pros and cons


Create commented sub-trees

Tree

/files/path/to/file/field1 = "value1"
/files/path/to/file/commented
/files/path/to/file/commented/field2 = "value2"
/files/path/to/file/comment = "a standard comment"


Implementation

Pros and cons


Defining comments vs. commented values

Trailing comments

Multi-lines comments

MediaWiki
GNU Free Documentation License 1.2