lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


It was thus said that the Great Geoff Leyland once stated:
> On 4/12/2013, at 8:10 am, Sean Conner <sean@conman.org> wrote:
> 
> > Yes, but you can read a line at a time and use LPeg to break the line
> > down.  You mentioned that there are issues with what constitutes a newline,
> > but there are ways around that.  One method I use is:
> 
> Thank you, that’s very much like the method I’m using, which is reassuring
> (provided we’re not fools seldom differing).  I’m not using LPeg, but only
> because I figured it was just one more dependency for what should be (ha
> ha) a simple format.  

  Even for such a simple format [1] I would still use LPeg since (to me)
it makes the parsing code much easier to follow and modify if need be (did
you realize you have to handle double quotes in a quoted string?).

> There’s also a bit of mucking around because there
> can be newlines embedded inside quoted fields.

  Yes, I missed that first time around.
  
> Sorry for not being clear initially: I know that the issues I mentioned
> are simple to overcome and I have working code.  Should I abandon that and
> adopt an existing solution, improve an existing solution, publish my own
> solution or just go back to my cave? 

  That, I can't tell you.  Working code trumps theoretical code any day. 
Only you can measure the amount of maintenance you are willing to do for any
code you write, vs. the time to adapt existing code to your project plus
follow later patches and versions (six of one, half dozen the other).  

  I did provide some LPeg code to parse a single record, plus some untested
(but should work) Lua code that drives it in another email message.  Feel
free to use it.

  -spc   

[1]	http://en.wikipedia.org/wiki/Comma-separated_values