lua-users home
lua-l archive

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

> 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.)

Exactly because it is generated automatically, shouldn't it be easy to
put the list in proper order? All you have to do is to order the entries by
decreasing token length.

-- Roberto