[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Proposal for lpeg
- From: albertmcchan <albertmcchan@...>
- Date: Tue, 6 Feb 2018 13:34:28 -0500
lpeg.P always match at beginning of string, maybe an efficient matching anywhere function ?
Example:
keywords = P'while' + 'repeat' + 'for'
to search keywords anywhere efficiently, skip all bad head chars
skip = 1 - S"wrf" -- set of skipped chars
--> lpeg.M(keywords) == P{ keywords + 1 * skip ^ 0 * V(1) }
lpeg.M(Cp() * keywords * Cp()) == position of first keyword
lpeg.M(C(keywords))^1 == capture all the keywords
it will be convenient to have lpeg go thru the lpeg object tree to build skip set,
and produce an efficient matching object.
If we do it by hand, and more keywords were added, skip have to be updated too.
with lpeg.M (if available), skip set is built on the fly, and always up-to-date