[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: More LPeg questions
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 16 Jun 2008 11:45:38 -0300
> The best I could do in LPeg is this:
> require "lpeg"
> word = lpeg.C (lpeg.R ("az")^1)
> phrase = word *
> " and " *
> lpeg.Cmt (word * lpeg.Cb (2),
> function (s, i, a, b) return a == b end)
> print (lpeg.match (phrase, "fish and chips")) --> nil
> print (lpeg.match (phrase, "fish and fish")) --> fish
> Is this the best way of achieving this?
In this particular case you can avoid the backreference:
phrase = lpeg.Cmt (word * "and" * word,
function (s, i, a, b) return a == b end)
But in the general case your solution is Ok. (See how 're' translates
> On the web page http://www.inf.puc-rio.br/~roberto/lpeg/re.html you
> mention that the lpeg.Cb is an experimental feature. What is its current
> status? The example at the bottom ("The next example mathes Lua long
> strings:") uses it, so presumably you are reasonably keen on it.
The overall concept (some form of backreference) will stay, but the
specific form will probably change. In particular, its use of numbers to
refer to back-captures is very difficult to use.
> LPeg is current version 0.8.1 - is there any projected release date for
> version 1? Presumably this will be a stable version with its features
Unfortunately there is no projected release date. I am still designing
some features in LPEG (specifically the backreference stuff), and that
can take some time to mature.
> I tried to write to Roberto privately about that, but unfortunately
> the anti-spam software at his email address rejected my email for some
> reason. Apparently my IP address in on some SORBS list, however my
> Internet provider is Telstra BigPond, the largest provider of Internet
> connectivity in Australia, and the operator of the telephone network.
I am very sorry about that. Can you give more details?