Multi-line LPeg CSV parser
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Multi-line LPeg CSV parser
- From: Joshua Jensen <jjensen@...>
- Date: 2009年5月01日 10:44:21 -0600
I started with the example in the LPeg manual for CSV parsing and tried
adding support to have it parse an entire buffer of multiple CSV lines:
local field = '"' * lpeg.Cs(((lpeg.P(1) - '"') + lpeg.P'""' / '"')^0) * '"' +
lpeg.C((1 - lpeg.S',\r\n"')^0)
local record = lpeg.Ct(field * (',' * field)^0) * (lpeg.P'\r\n' + lpeg.P'\n' + -1)
local all = lpeg.Ct(record^0)
This fails, of course, with a "loop body may accept empty string" error.
What is the proper solution for making that error go away?
Thanks.
Josh