From 7a81ced5143c056c020b94ea2424964edcc218a7 Mon Sep 17 00:00:00 2001 From: yhirose Date: Sun, 22 Feb 2015 22:48:41 -0500 Subject: [PATCH] Added csv.peg. --- grammar/csv.peg | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 grammar/csv.peg diff --git a/grammar/csv.peg b/grammar/csv.peg new file mode 100644 index 0000000..c915aa4 --- /dev/null +++ b/grammar/csv.peg @@ -0,0 +1,18 @@ +# +# CSV grammar based on RFC 4180 (http://www.ietf.org/rfc/rfc4180.txt) +# + +file <- (header NL)? record (NL record)* NL? +header <- name (COMMA name)* +record <- field (COMMA field)* +name <- field +field <- escaped / non_escaped +escaped <- DQUOTE (TEXTDATA / COMMA / CR / LF / TWO_DQUOTE)* DQUOTE +non_escaped <- TEXTDATA* +COMMA <- ',' +CR <- '\r' +DQUOTE <- '"' +LF <- '\n' +NL <- CR LF / CR / LF +TEXTDATA <- [\x20-\x21] / [\x23-\x2B] / [\x2D-\x7E] +TWO_DQUOTE <- '"' '"'