ChopDat is a work in progress parsing library. It currently supports only CSV (Comma Separated Values) parsing, but is soon going to support many other file formats.
The library provides CSV parsing features through a recursive descent approach. The supported context-free grammar is a simplified version of the official CSV grammar from RFC 4180, written in BNF (Backus-Naur Form); in classic matemathical language:
records = enclosed_token COMMA records / enclosed_token CRLF / e
enclosed_token = DQUOTE token DQUOTE
token = TEXTDATA token / TEXTDATA
CRLF = %x0D%x0A
COMMA = %x2C
DQUOTE = %x22
TEXTDATA = %x00-09 / %x0B-0C / %x0E-21 / %x23-10FFFF
This simplified grammar assumes that:
- a CSV file is a sequence of
records(including the empty sequence), - a record is structured into
enclosed_token(s) separated byCOMMA(s) and ending in aCRLF(i.e. Carriage Return, Line Feed), - an
enclosed_tokenis structured as atokenenclosed inDQUOTE(s) (double quotes), - a
tokenis a sequence of at least one unicode character, except from double quotes, carriage returns and new lines.
Imposing such limitations to the original grammar, thus to the language it generates, largely eases the complexity of our parser. Nonetheless, being this CSV “dialect” quite common, this parser allows real world usage.