Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / csv.aug
1 (*
2 Module: CSV
3   Generic CSV lens collection
4
5 Author: Raphael Pinson <raphael.pinson@camptocamp.com>
6
7 About: Reference
8   https://tools.ietf.org/html/rfc4180
9
10 About: License
11    This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14    To be documented
15
16 About: Configuration files
17
18 About: Examples
19    The <Test_CSV> file contains various examples and tests.
20
21 Caveats:
22    No support for files without an ending CRLF
23 *)
24 module CSV =
25
26 (* View: eol *)
27 let eol = Util.del_str "\n"
28
29 (* View: comment *)
30 let comment = Util.comment
31             | [ del /#[ \t]*\r?\n/ "#\n" ]
32
33 (* View: entry
34      An entry of fields, quoted or not *)
35 let entry (sep_str:string) =
36   let field = [ seq "field" . store (/[^"#\r\n]/ - sep_str)* ]
37             | [ seq "field" . store /("[^"#]*")+/ ]
38   in let sep = Util.del_str sep_str
39   in [ seq "entry" . counter "field" . Build.opt_list field sep . eol ]
40
41 (* View: lns
42      The generic lens, taking the separator as a parameter *)
43 let lns_generic (sep:string) = (comment | entry sep)*
44
45 (* View: lns
46      The comma-separated value lens *)
47 let lns = lns_generic ","
48
49 (* View: lns_semicol
50      A semicolon-separated value lens *)
51 let lns_semicol = lns_generic ";"