Util

Generic module providing useful primitives

Author: David Lutterkort

Summary
UtilGeneric module providing useful primitives
LicenseThis file is licensed under the LGPLv2+, like the rest of Augeas.
del_strDelete a string and default to it
del_wsDelete mandatory whitespace
del_ws_spcDelete mandatory whitespace, default to single space
del_ws_tabDelete mandatory whitespace, default to single tab
del_opt_wsDelete optional whitespace
eolDelete end of line, including optional trailing whitespace
doseolDelete end of line with optional carriage return, including optional trailing whitespace
indentDelete indentation, including leading whitespace
CommentThis is a general definition of comment It allows indentation for comments, removes the leading and trailing spaces of comments and stores them in nodes, except for empty comments which are ignored together with empty lines
comment_generic_seteolMap comments and set default comment sign
comment_genericMap comments and set default comment sign
commentMap comments into “#comment” nodes
comment_noindentMap comments into “#comment” nodes, without indentation
comment_eolMap eol comments into “#comment” nodes Add a space before # for end of line comments
comment_or_eolA comment_eol or eol, with an optional empty comment
comment_multilineA C-style multiline comment
comment_c_styleA comment line, C-style
empty_genericA generic definition of empty Map empty lines, including empty comments
empty_generic_re
emptyMap empty lines, including empty comments
empty_c_styleMap empty lines, including C-style empty comment
empty_generic_dosA generic definition of empty with dos newlines Map empty lines, including empty comments
empty_dos
Split
delim
Exclusions
stdexclExclusion for files that are commonly not wanted/needed

License

This file is licensed under the LGPLv2+, like the rest of Augeas.

del_str

let del_str (s:string) = del s s

Delete a string and default to it

Parameters

s:stringthe string to delete and default to

del_ws

let del_ws = del /[ \t]+/

Delete mandatory whitespace

del_ws_spc

let del_ws_spc = del_ws " "

Delete mandatory whitespace, default to single space

del_ws_tab

let del_ws_tab = del_ws "\t"

Delete mandatory whitespace, default to single tab

del_opt_ws

let del_opt_ws = del /[ \t]*/

Delete optional whitespace

eol

let eol = del /[ \t]*\n/ "\n"

Delete end of line, including optional trailing whitespace

doseol

let doseol = del /[ \t]*\r?\n/ "\n"

Delete end of line with optional carriage return, including optional trailing whitespace

indent

let indent = del /[ \t]*/ ""

Delete indentation, including leading whitespace

Comment

This is a general definition of comment It allows indentation for comments, removes the leading and trailing spaces of comments and stores them in nodes, except for empty comments which are ignored together with empty lines

comment_generic_seteol

let comment_generic_seteol (r:regexp) (d:string) (eol:lens) = [ label "#comment" . del r d . store /([^ \t\r\n].*[^ \t\r\n]|[^ \t\r\n])/ . eol ]

Map comments and set default comment sign

comment_generic

let comment_generic (r:regexp) (d:string) = comment_generic_seteol r d doseol

Map comments and set default comment sign

comment

let comment = comment_generic /[ \t]*#[ \t]*/ "# "

Map comments into “#comment” nodes

comment_noindent

let comment_noindent = comment_generic /#[ \t]*/ "# "

Map comments into “#comment” nodes, without indentation

comment_eol

let comment_eol = comment_generic /[ \t]*#[ \t]*/ " # "

Map eol comments into “#comment” nodes Add a space before # for end of line comments

comment_or_eol

let comment_or_eol = comment_eol | (del /[ \t]*(#[ \t]*)?\n/ "\n")

A comment_eol or eol, with an optional empty comment

comment_multiline

let comment_multiline = let mline_re = (/[^ \t\r\n].*[^ \t\r\n]|[^ \t\r\n]/ - /.*\*\/.*/) in let mline = [ seq "mline" . del /[ \t\r\n]*/ "\n" . store mline_re ] in [ label "#mcomment" . del /[ \t]*\/\*/ "/*" . counter "mline" . mline . (eol . mline)* . del /[ \t\r\n]*\*\/[ \t]*\r?\n/ "\n*/\n" ]

A C-style multiline comment

comment_c_style

let comment_c_style = comment_generic /[ \t]*\/\/[ \t]*/ "// "

A comment line, C-style

empty_generic

let empty_generic (r:regexp) = [ del r "" . del_str "\n" ]

A generic definition of empty Map empty lines, including empty comments

empty_generic_re

let empty_generic_re = /[ \t]*#?[ \t]*/

empty

let empty = empty_generic empty_generic_re

Map empty lines, including empty comments

empty_c_style

let empty_c_style = empty_generic /[ \t]*((\/\/)|(\/\*[ \t]*\*\/))?[ \t]*/

Map empty lines, including C-style empty comment

empty_generic_dos

let empty_generic_dos (r:regexp) = [ del r "" . del /\r?\n/ "\n" ]

A generic definition of empty with dos newlines Map empty lines, including empty comments

empty_dos

let empty_dos = empty_generic_dos /[ \t]*#?[ \t]*/

Split

delim

let delim (op:string) = del (/[ \t]*/ . op . /[ \t]*/) (" " . op . " ")

Exclusions

stdexcl

let stdexcl = (excl "*~") . (excl "*.rpmnew") . (excl "*.rpmsave") . (excl "*.dpkg-old") . (excl "*.dpkg-new") . (excl "*.dpkg-bak") . (excl "*.dpkg-dist") . (excl "*.augsave") . (excl "*.augnew") . (excl "*.bak") . (excl "*.old") . (excl "#*#")

Exclusion for files that are commonly not wanted/needed

let del_str (s:string) = del s s
Delete a string and default to it
let del_ws = del /[ \t]+/
Delete mandatory whitespace
let del_ws_spc = del_ws " "
Delete mandatory whitespace, default to single space
let del_ws_tab = del_ws "\t"
Delete mandatory whitespace, default to single tab
let del_opt_ws = del /[ \t]*/
Delete optional whitespace
let eol = del /[ \t]*\n/ "\n"
Delete end of line, including optional trailing whitespace
let doseol = del /[ \t]*\r?\n/ "\n"
Delete end of line with optional carriage return, including optional trailing whitespace
let indent = del /[ \t]*/ ""
Delete indentation, including leading whitespace
let comment_generic_seteol (r:regexp) (d:string) (eol:lens) = [ label "#comment" . del r d . store /([^ \t\r\n].*[^ \t\r\n]|[^ \t\r\n])/ . eol ]
Map comments and set default comment sign
let comment_generic (r:regexp) (d:string) = comment_generic_seteol r d doseol
Map comments and set default comment sign
let comment = comment_generic /[ \t]*#[ \t]*/ "# "
Map comments into “#comment” nodes
let comment_noindent = comment_generic /#[ \t]*/ "# "
Map comments into “#comment” nodes, without indentation
let comment_eol = comment_generic /[ \t]*#[ \t]*/ " # "
Map eol comments into “#comment” nodes Add a space before # for end of line comments
let comment_or_eol = comment_eol | (del /[ \t]*(#[ \t]*)?\n/ "\n")
A comment_eol or eol, with an optional empty comment
let comment_multiline = let mline_re = (/[^ \t\r\n].*[^ \t\r\n]|[^ \t\r\n]/ - /.*\*\/.*/) in let mline = [ seq "mline" . del /[ \t\r\n]*/ "\n" . store mline_re ] in [ label "#mcomment" . del /[ \t]*\/\*/ "/*" . counter "mline" . mline . (eol . mline)* . del /[ \t\r\n]*\*\/[ \t]*\r?\n/ "\n*/\n" ]
A C-style multiline comment
let comment_c_style = comment_generic /[ \t]*\/\/[ \t]*/ "// "
A comment line, C-style
let empty_generic (r:regexp) = [ del r "" . del_str "\n" ]
A generic definition of empty Map empty lines, including empty comments
let empty = empty_generic empty_generic_re
Map empty lines, including empty comments
let empty_generic_re = /[ \t]*#?[ \t]*/
let empty_c_style = empty_generic /[ \t]*((\/\/)|(\/\*[ \t]*\*\/))?[ \t]*/
Map empty lines, including C-style empty comment
let empty_generic_dos (r:regexp) = [ del r "" . del /\r?\n/ "\n" ]
A generic definition of empty with dos newlines Map empty lines, including empty comments
let empty_dos = empty_generic_dos /[ \t]*#?[ \t]*/
let delim (op:string) = del (/[ \t]*/ . op . /[ \t]*/) (" " . op . " ")
let stdexcl = (excl "*~") . (excl "*.rpmnew") . (excl "*.rpmsave") . (excl "*.dpkg-old") . (excl "*.dpkg-new") . (excl "*.dpkg-bak") . (excl "*.dpkg-dist") . (excl "*.augsave") . (excl "*.augnew") . (excl "*.bak") . (excl "*.old") . (excl "#*#")
Exclusion for files that are commonly not wanted/needed
Close