lua-users home
lua-l archive

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




On 2017-07-03 08:55 PM, Sean Conner wrote:
It was thus said that the Great Sean Conner once stated:
It was thus said that the Great Dirk Laurie once stated:
2017-07-03 21:35 GMT+02:00 Soni L. <fakedme@gmail.com>:

That was a feature request. And that trick doesn't work for captures
beyond 1 without introducing nils or a massive performance hit.
Would the requested feature make `pat/-2` drop the second capture
or the first two captures?
   While I'm sympathetic to the proposal, I don't think it can be done
without a drastic redesign of LPeg at the lowest level.  For example:
   Um ... actually, I retract what I said.  The required functionality is
quite easy to get:

	a = lpeg.C"a"
	b = lpeg.C"b"
	c = (a * b * a) / function(a,b,c) return b end   -- [ patt / -2 ]
	d = (a * b * a) / function(a,b,c) return b,c end -- [ patt / -1 ]
	e = (a * b * a) / function(a,b,c) return c end   -- [ (patt / -1) / -1 ]

$ lua -l lpeg
Lua 5.3.4  Copyright (C) 1994-2017 Lua.org, PUC-Rio
> (lpeg.P"a"/function(a,b) return b end):match("a")
nil

It was supposed to error. And no, you can't just "if not b then error()", because this is a thing:

> (lpeg.C(lpeg.P"a" * lpeg.Cc(nil))/2):match("a")
nil

And so you go for select(), and now we're back at "doesn't work for captures beyond 1 without introducing nils or a massive performance hit."


   -spc (Mixed this up with an earlier request --- sorry about that)



--
Disclaimer: these emails may be made public at any given time, with or without reason. If you don't agree with this, DO NOT REPLY.