diff options
Diffstat (limited to 'inttest/neotoma1/src/csv.peg')
-rw-r--r-- | inttest/neotoma1/src/csv.peg | 31 |
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] ~; |