Published
Edited
Sep 23, 2021
6 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
// DQUOTE = %x22 ;as per section 6.1 of RFC 2234
dquote = P.literal('"')
Insert cell
_2dquote = P.literal('""')
Insert cell
// LF = %x0A ;as per section 6.1 of RFC 2234
lf = P.literal('\n')
Insert cell
// CR = %x0D ;as per section 6.1 of RFC 2234
cr = P.literal('\r')
Insert cell
// CRLF = CR LF ;as per section 6.1 of RFC 2234
crlf = P.either(cr, lf)
Insert cell
// TEXTDATA = %x20-21 / %x23-2B / %x2D-7E
textdata = P.charRanges(['\x20', '\x21'], ['\x23', '\x2b'], ['\x2d', '\x7e'])
Insert cell
// COMMA = %x2C
comma = P.literal(',')
Insert cell
// non-escaped = *TEXTDATA
nonEscaped = P.join(P.star(textdata))
Insert cell
// escaped = DQUOTE *(TEXTDATA / COMMA / CR / LF / 2DQUOTE) DQUOTE
escaped = P.sorrounded1(dquote, P.join(P.star(P.union(textdata, comma, cr, lf, P.map(_2dquote, () => '"')))))
Insert cell
// field = (escaped / non-escaped)
field = P.either(escaped, nonEscaped)
Insert cell
// record = field *(COMMA field)
record = P.separated1(comma, field)
Insert cell
// file = [header CRLF] record *(CRLF record) [CRLF]
file = P.separated1(crlf, record)
Insert cell
parse = P.exhaustive(P.trim(file))
Insert cell
Insert cell
P = import("https://cdn.skypack.dev/@prelude/parser@v1.2.1")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more