|
Packit Service |
a2ae7a |
(* Augeas module for editing Java properties files
|
|
Packit Service |
a2ae7a |
Author: Craig Dunn <craig@craigdunn.org>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Limitations:
|
|
Packit Service |
a2ae7a |
- doesn't support \ alone on a line
|
|
Packit Service |
a2ae7a |
- values are not unescaped
|
|
Packit Service |
a2ae7a |
- multi-line properties are broken down by line, and can't be replaced with a single line
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
See format info: http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html#load(java.io.Reader)
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
module Properties =
|
|
Packit Service |
a2ae7a |
(* Define some basic primitives *)
|
|
Packit Service |
a2ae7a |
let empty = Util.empty_generic_dos /[ \t]*[#!]?[ \t]*/
|
|
Packit Service |
a2ae7a |
let eol = Util.doseol
|
|
Packit Service |
a2ae7a |
let hard_eol = del /\r?\n/ "\n"
|
|
Packit Service |
a2ae7a |
let sepch = del /([ \t]*(=|:)|[ \t])/ "="
|
|
Packit Service |
a2ae7a |
let sepspc = del /[ \t]/ " "
|
|
Packit Service |
a2ae7a |
let sepch_ns = del /[ \t]*(=|:)/ "="
|
|
Packit Service |
a2ae7a |
let sepch_opt = del /[ \t]*(=|:)?[ \t]*/ "="
|
|
Packit Service |
a2ae7a |
let value_to_eol_ws = store /(:|=)[^\r\n]*[^ \t\r\n\\]/
|
|
Packit Service |
a2ae7a |
let value_to_bs_ws = store /(:|=)[^\n]*[^\\\n]/
|
|
Packit Service |
a2ae7a |
let value_to_eol = store /([^ \t\n:=][^\n]*[^ \t\r\n\\]|[^ \t\r\n\\:=])/
|
|
Packit Service |
a2ae7a |
let value_to_bs = store /([^ \t\n:=][^\n]*[^\\\n]|[^ \t\n\\:=])/
|
|
Packit Service |
a2ae7a |
let indent = Util.indent
|
|
Packit Service |
a2ae7a |
let backslash = del /[\\][ \t]*\n/ "\\\n"
|
|
Packit Service |
a2ae7a |
let opt_backslash = del /([\\][ \t]*\n)?/ ""
|
|
Packit Service |
a2ae7a |
let entry = /([^ \t\r\n:=\/!#\\]|[\\]:|[\\]=|[\\][\t ]|[\\][^\/\r\n])+/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let multi_line_entry =
|
|
Packit Service |
a2ae7a |
[ indent . value_to_bs? . backslash ] .
|
|
Packit Service |
a2ae7a |
[ indent . value_to_bs . backslash ] * .
|
|
Packit Service |
a2ae7a |
[ indent . value_to_eol . eol ] . value " < multi > "
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let multi_line_entry_ws =
|
|
Packit Service |
a2ae7a |
opt_backslash .
|
|
Packit Service |
a2ae7a |
[ indent . value_to_bs_ws . backslash ] + .
|
|
Packit Service |
a2ae7a |
[ indent . value_to_eol . eol ] . value " < multi_ws > "
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* define comments and properties*)
|
|
Packit Service |
a2ae7a |
let bang_comment = [ label "!comment" . del /[ \t]*![ \t]*/ "! " . store /([^ \t\n].*[^ \t\r\n]|[^ \t\r\n])/ . eol ]
|
|
Packit Service |
a2ae7a |
let comment = ( Util.comment | bang_comment )
|
|
Packit Service |
a2ae7a |
let property = [ indent . key entry . sepch . ( multi_line_entry | indent . value_to_eol . eol ) ]
|
|
Packit Service |
a2ae7a |
let property_ws = [ indent . key entry . sepch_ns . ( multi_line_entry_ws | indent . value_to_eol_ws . eol ) ]
|
|
Packit Service |
a2ae7a |
let empty_property = [ indent . key entry . sepch_opt . hard_eol ]
|
|
Packit Service |
a2ae7a |
let empty_key = [ sepch_ns . ( multi_line_entry | indent . value_to_eol . eol ) ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* setup our lens and filter*)
|
|
Packit Service |
a2ae7a |
let lns = ( empty | comment | property_ws | property | empty_property | empty_key ) *
|