[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Greedy matching with LPEG
- From: David Given <dg@...>
- Date: Mon, 16 Feb 2009 23:21:18 +0000
Okay, here's a very noddy LPEG question.
I have a long list of tokens ("foo", "foobar", "fooj"), and I wish to
construct a pattern that will match the longest of these.
I can this:
p = P("foo") + P("foobar") + P("fooj")
However, if I match "foobars" against this, I get "foo" --- as I'd
expect, given that + is described as being ordered in the docs.
How can I do a greedy match rather than an ordered one? That is, I don't
care about the order; I just want the longest applicable alternative to
match.
(Yes, I'm aware I can simply change the order of my definition, but it's
actually quite long and is generated automatically, so I'd rather not do
this.)
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│ "A line dancer near a graduated cylinder, the blithe spirit inside
│ some wheelbarrow, and a tomato are what made America great!" ---
│ received via spam
Attachment:
signature.asc
Description: OpenPGP digital signature