Permalink
Browse files

Use Build.block_generic and include semicolon in comment_or_eol

  • Loading branch information...
1 parent ba92a2d commit 17a7706d540acf2b3b1b609ca2a85233a540b2b7 @raphink raphink committed Nov 13, 2012
Showing with 43 additions and 19 deletions.
  1. +43 −19 bacula.aug
View
@@ -25,7 +25,6 @@ module Bacula =
autoload xfm
let indent = Util.del_opt_ws "\t"
-
let equal = del /[ \t]*=[ \t]*/ " = "
let key_name = /[a-zA-Z][a-zA-Z ]+[a-zA-Z]/
let dquote = del /"?/ "\""
@@ -35,15 +34,29 @@ module Bacula =
let keyvalue = key key_name . equal . val
let include = label "@include" . del "@" "@" . store /[^ #\t\n@};]+/
- let semicolon = [ del /[ \t]*;/ ";" ]
- let line (sto:lens) = [ indent . sto . (semicolon|Util.comment_or_eol) ]
- let brackets (sto:lens) = del /[ \n\t]*\{\n*/ " {\n"
- . (sto|Util.comment)
- . ((sto|Util.empty|Util.comment)*
- . (sto|Util.comment))?
- . del /[ \n\t]*}/ "\n}"
-
- let directive = [ key /[a-zA-Z]+/ . brackets (line keyvalue |line include) ]
+ let eol = del /[ \t]*(;|(#[ \t]*)?\n)/ "\n"
+ let comment_or_eol = Util.comment_eol | eol
+
+ let line (sto:lens) = [ sto . comment_or_eol ]
+
+ let directive =
+ let entry = Util.empty | (indent . (line keyvalue|line include))
+ in let entry_noindent = line keyvalue|line include
+ in let entry_noindent_noeol = [keyvalue] | [include]
+ in let entry_noeol = indent . entry_noindent_noeol
+ in [ key /[a-zA-Z]+/
+ . Build.block_generic
+ entry (* entry *)
+ entry_noindent (* entry_noindent *)
+ entry_noeol (* entry_noeol *)
+ entry_noindent_noeol (* entry_noindent_noeol *)
+ Util.comment (* comment *)
+ Util.comment_noindent (* comment_noindent *)
+ Build.block_ldelim_re (* ldelim_re *)
+ Build.block_rdelim_re (* rdelim_re *)
+ " {\n\t" (* ldelim_default *)
+ Build.block_rdelim_default (* rdelim_default *)
+ . Util.eol ]
let lns = (directive|Util.empty|Util.comment)*
@@ -52,53 +65,64 @@ module Bacula =
let xfm = transform lns filter
- (* basic directive *)
- test Bacula.lns get "Storage {\n Name = kaki-sd\n}" =
+ test (Bacula.line keyvalue) get "Name = kaki-sd\n" =
+ {"Name" = "kaki-sd"}
+
+ test (Bacula.line include) get "@foobar\n" =
+ {"@include" = "foobar"}
+
+ test (Bacula.line keyvalue) get "Name = kaki-sd;" =
+ {"Name" = "kaki-sd"}
+
+ test (Bacula.line include) get "@foobar;" =
+ {"@include" = "foobar"}
+
+ test Bacula.lns get "Storage {\n Name = kaki-sd\n}\n" =
{"Storage"
{"Name" = "kaki-sd"}
}
(* value can have quotes *)
- test Bacula.lns get "Storage {\n Name = \"kaki sd\"\n}" =
+ test Bacula.lns get "Storage {\n Name = \"kaki sd\"\n}\n" =
{"Storage"
{"Name" = "kaki sd"}
}
(* whitespace in key *)
- test Bacula.lns get "Storage {\n Pid Directory = kaki sd\n}" =
+ test Bacula.lns get "Storage {\n Pid Directory = kaki sd\n}\n" =
{"Storage"
{"Pid Directory" = "kaki sd"}
}
(* semicolon *)
- test Bacula.lns get "Storage {\n Name = kaki-sd;\n}" =
+ test Bacula.lns get "Storage {\n Name = kaki-sd;\n}\n" =
{"Storage"
{"Name" = "kaki-sd" {} }
}
(* inline comment *)
- test Bacula.lns get "Storage {\n Name = kaki-sd # just a comment\n}" =
+ test Bacula.lns get "Storage {\n Name = kaki-sd # just a comment\n}\n" =
{"Storage"
{"Name" = "kaki-sd"
{ "#comment" = "just a comment"} }
}
(* multiple values *)
- test Bacula.lns get "Storage {\n Name = kaki sd\nFoo = moo\n}" =
+ test Bacula.lns get "Storage {\n Name = kaki sd\nFoo = moo\n}\n" =
{"Storage"
{"Name" = "kaki sd"}
{"Foo" = "moo"}
}
(* newline comment *)
- test Bacula.lns get "Storage {\n Name = kaki sd\n# just a comment\n}" =
+ test Bacula.lns get "Storage {\n Name = kaki sd\n# just a comment\n}\n" =
{"Storage"
{"Name" = "kaki sd" }
{"#comment" = "just a comment" }
}
(* TODO: include statements *)
- test Bacula.lns get "Storage {\n @/etc/foo.conf\n}" =
+ test Bacula.lns get "Storage {\n @/etc/foo.conf\n}\n" =
{"Storage"
{"@include" = "/etc/foo.conf"}
}

0 comments on commit 17a7706

Please sign in to comment.