Added csv.peg.

This commit is contained in:
yhirose 2015-02-22 22:48:41 -05:00
parent 64e7274b1d
commit 7a81ced514

18
grammar/csv.peg Normal file
View File

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