lua-users home
lua-l archive

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

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

(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

┌─── ───── ─────
│ "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