Last active
December 18, 2015 22:18
-
-
Save raphink/5853039 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mechanicalduck = | |
let values = | |
(* semicolons are allowed if they are not preceded or followed by a space *) | |
let allowed_semicolon = /[^\n ];/ | /;[^\n ]/ | |
(* anything but a semicolon or a newline *) | |
in let no_semicolon = /[^\n;]/ | |
(* values can be either no_semicolon or allowed_semicolon *) | |
in let val_re = (no_semicolon | allowed_semicolon)* | |
(* a value is a seq entry that stores a val_re *) | |
in let val = [ seq "val" . store val_re ] | |
(* the separator is the exact string " ; " *) | |
in let semicolon = Util.del_str " ; " | |
(* entries are an optional list of values *) | |
in Build.list val semicolon | val | |
(* a single value *) | |
test values get "value1" = | |
{ "1" = "value1" } | |
(* a single value containing a semicolon *) | |
test values get "value1;value2" = | |
{ "1" = "value1;value2" } | |
(* two values *) | |
test values get "value1 ; value2" = | |
{ "1" = "value1" } | |
{ "2" = "value2" } | |
(* two values, with a semicolon *) | |
test values get "value;1 ; value2" = | |
{ "1" = "value;1" } | |
{ "2" = "value2" } | |
(* two values, with semicolons and tabs *) | |
test values get "value ;1 ; \tvalue\t 2;" = | |
{ "1" = "value ;1 " } | |
{ "2" = "\tvalue\t 2;" } | |
(* Newlines are not part of values *) | |
test values get "value\n1" = * | |
(* three simple values *) | |
test values get "value1 ; value2 ; value3" = | |
{ "1" = "value1" } | |
{ "2" = "value2" } | |
{ "3" = "value3" } | |
(* three values, including an empty one *) | |
test values get " value1 ; ; value2 " = | |
{ "1" = " value1" } | |
{ "2" = "" } | |
{ "3" = "value2 " } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment