diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2013-07-14 10:01:25 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2013-07-14 10:01:25 +0200 |
commit | e00d066f7a7cb1ffd8df94d90e16565c3dedeec7 (patch) | |
tree | c9893c780ccc05c8f5402b8bf09caf361cbeea86 /lualibs-lpeg.lua | |
parent | f2f35fe3d8a1c5ce74ddbb8eef3cad2b18a379dc (diff) | |
download | lualibs-e00d066f7a7cb1ffd8df94d90e16565c3dedeec7.tar.gz |
sync with Context as of 2013-07-14
Diffstat (limited to 'lualibs-lpeg.lua')
-rw-r--r-- | lualibs-lpeg.lua | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/lualibs-lpeg.lua b/lualibs-lpeg.lua index 7be86d3..b33df96 100644 --- a/lualibs-lpeg.lua +++ b/lualibs-lpeg.lua @@ -13,6 +13,19 @@ if not modules then modules = { } end modules ['l-lpeg'] = { lpeg = require("lpeg") +-- The latest lpeg doesn't have print any more, and even the new ones are not +-- available by default (only when debug mode is enabled), which is a pitty as +-- as it helps bailign down bottlenecks. Performance seems comparable, although +-- +-- local p = lpeg.C(lpeg.P(1)^0 * lpeg.P(-1)) +-- local a = string.rep("123",10) +-- lpeg.match(p,a) +-- +-- is nearly 20% slower and also still suboptimal (i.e. a match that runs from +-- begin to end, one of the cases where string matchers win). + +if not lpeg.print then function lpeg.print(...) print(lpeg.pcode(...)) end end + -- tracing (only used when we encounter a problem in integration of lpeg in luatex) -- some code will move to unicode and string @@ -212,7 +225,7 @@ patterns.propername = (uppercase + lowercase + underscore) * (uppercase + low patterns.somecontent = (anything - newline - space)^1 -- (utf8char - newline - space)^1 patterns.beginline = #(1-newline) -patterns.longtostring = Cs(whitespace^0/"" * nonwhitespace^0 * ((whitespace^0/" " * (patterns.quoted + nonwhitespace)^1)^0)) +patterns.longtostring = Cs(whitespace^0/"" * ((patterns.quoted + nonwhitespace^1 + whitespace^1/"" * (P(-1) + Cc(" ")))^0)) local function anywhere(pattern) --slightly adapted from website return P { P(pattern) + 1 * V(1) } |