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 Egor Skriptunoff once stated:
> On Sat, Oct 14, 2017 at 11:13 AM, Sean Conner wrote:
> >
> >   First off, %z was deprecated in Lua 5.2 (see section 8.2), and it's not
> > mentioned at all in the Lua 5.3 manual (although my version of Lua 5.3
> > does run the above code).
> 
> Removing %z and %Z from Lua has only disadvantages.
> Actually, we will have to complicate our scripts to check Lua version in
> runtime and apply version-specific pattern to make our code work in all Lua
> versions.
> That's a headache.
> 
> I see no benefit of removing %z and %Z from Lua .

  I have no opinion on this.  I've never used %z/%Z in my code.  Just a data
point in this discussion.

> >   Here is some code that works (and maybe even Soni would like it, as
> > it's not limited to '"' as the quote character---it can be any string,
> > and said string can appear escaped!):
> >
> Your code does not look like a simplification of Sony's code  ;-)

  If by "simplification" you mean "shorter than 
  
  text:gsub("\\?.", {[quote]="\0"}):match("%z()", start_pos)
  
then yes, that is true.  But there are issues with that code frament. 
First, you are generating a modified string of the original data.  Second,
there are failure modes, for instance:

	print(end_of_string_literal ('"\0\0" is the string',2,'"'))

should print 5, not 3.  Admittedly, this is a corner case, but the code I
presented does handle it correctly.  Third, I don't think the as presented
is all that difficult.  Sure, it may look unfamiliar, but the code, with the
LPeg manual [1] as reference, one should be able to puzzle out how the code
works (like I had to do with your version).

  -spc (The LPeg version has the added benefit of being composible with
	other LPeg expressions, something that the one based on Lua patterns
	cannot do.)

[1]	http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html