summaryrefslogtreecommitdiff
path: root/inttest/neotoma1/src/csv.peg
blob: 000c00f5bf92063808dd5dbc4d0a47b3b58f373f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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] ~;