https://github.com/puripuri2100/satysfi-csv
A CSV reader and writer for SATySFi.
https://github.com/puripuri2100/satysfi-csv
csv parser satsyfi
Last synced: 6 months ago
JSON representation
A CSV reader and writer for SATySFi.
- Host: GitHub
- URL: https://github.com/puripuri2100/satysfi-csv
- Owner: puripuri2100
- License: mit
- Created: 2021-10-17T03:41:48.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2021-10-18T12:51:05.000Z (almost 5 years ago)
- Last Synced: 2025-08-20T09:34:15.764Z (11 months ago)
- Topics: csv, parser, satsyfi
- Homepage:
- Size: 11.7 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# satysfi-csv
A CSV reader and writer for SATySFi.
# install
You can install csv package with [Satyrographos](https://github.com/na4zagin3/satyrographos).
```sh
opam update
opam install satysfi-csv
satyrographos install
```
OR
```sh
opam pin add "git+https://github.com/puripuri2100/satysfi-csv.git"
opam install satysfi-csv
satyrographos install
```
After installation, you can import this package by writing the code in preamble.
```
@require: csv/csv
```
# usage
Use `CSV.parser` function to read the CSV.
`CSV.parser` function returns `((string list) list) csv-parser-error result` type.
`csv-parser-error` type is defined as follows:
```
type csv-parser-erro =
| CSVParserErrorUnExpectedChar of int * string
| CSVParserErrorEOI
```
`'ok 'err result` type is defined in [satysfi-base/base.satyg](https://github.com/nyuichi/satysfi-base/blob/master/src/base.satyg#L49). Use the functions provided by [satysfi-base/result.satyg](https://github.com/nyuichi/satysfi-base/blob/master/src/result.satyg) when operating the `result` type.
```
let csv = `1,2,3
a,"b
c",""d",e",f""`
let csv-data = CSV.parser csv
% =>
%Ok([
% [`1`; `2`; `3`];
% [`a`; `b
%c`; `d",e",f`]
%])
```
You can change the delimiter of CSV:
```
let csv = `1,000:2,000:3,000
a:"b
c":""d":e",f""`
let csv-data = CSV.parser ?:(`:`) csv
% =>
%Ok([
% [`1,000`; `2,000`; `3,000`];
% [`a`; `b
%c`; `d",e",f`]
%])
```
Use `CSV.printer` function to write the CSV data.
`CSV.printer` is of type `string ?-> (string list) list -> string`
```
let data = [
[`1`; `2`; `3`];
[`a"b`; `a"
c"d`; `e
f`];
]
let csv = CSV.printer data
% ==>
%`1,2,3
%""a"b"",""a"
%c"d"","e
%f"`
% You can change the delimiter of CSV:
let csv2 = CSV.printer ?:(`:`) data
% ==>
%`1:2:3
%""a"b"":""a"
%c"d"":"e
%f"`
```
---
This software released under the [MIT license](https://github.com/puripuri2100/satysfi-csv/blob/master/LICENSE).
Copyright (c) 2021 Naoki Kaneko (a.k.a. "puripuri2100")