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 <- '"' '"'