summaryrefslogtreecommitdiff
path: root/inttest/neotoma1/src/csv.peg
diff options
context:
space:
mode:
authorLuis Rascão <luis.rascao@gmail.com>2015-08-13 22:11:52 +0100
committerLuis Rascão <luis.rascao@gmail.com>2016-02-13 12:18:06 +0000
commitf5bc6df43989e53e60536674bf3c0f212b8962b9 (patch)
treea562197388393344cb94196365a18182c8baa7b8 /inttest/neotoma1/src/csv.peg
parentc83bacb98b0b0fafb5c57fb9cf45301b74b84cd6 (diff)
downloadrebar-f5bc6df43989e53e60536674bf3c0f212b8962b9.tar.gz
Add neotoma regression test
Integration regression test that checks for correct generation of .erl files from .peg ones and that they are cleaned up.
Diffstat (limited to 'inttest/neotoma1/src/csv.peg')
-rw-r--r--inttest/neotoma1/src/csv.peg31
1 files changed, 31 insertions, 0 deletions
diff --git a/inttest/neotoma1/src/csv.peg b/inttest/neotoma1/src/csv.peg
new file mode 100644
index 0000000..000c00f
--- /dev/null
+++ b/inttest/neotoma1/src/csv.peg
@@ -0,0 +1,31 @@
+rows <- head:row tail:(crlf row)* / ''
+`
+case Node of
+ [] -> [];
+ [""] -> [];
+ _ ->
+ Head = proplists:get_value(head, Node),
+ Tail = [R || [_,R] <- proplists:get_value(tail, Node)],
+ [Head|Tail]
+end
+`;
+
+row <- head:field tail:(field_sep field)* / ''
+`
+case Node of
+ [] -> [];
+ [""] -> [];
+ _ ->
+ Head = proplists:get_value(head, Node),
+ Tail = [F || [_,F] <- proplists:get_value(tail, Node)],
+ [Head|Tail]
+end
+`;
+field <- quoted_field / (!field_sep !crlf .)* `iolist_to_binary(Node)`;
+quoted_field <- '"' string:('""' / (!'"' .))* '"'
+`
+ String = proplists:get_value(string, Node),
+ re:replace(String, "[\"]{2}", "\"",[global, {return, binary}])
+`;
+field_sep <- ',' ~;
+crlf <- [\r]? [\n] ~;