lua-users home
lua-l archive

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


On Wed, 3 Nov 2010, Roberto Ierusalimschy wrote:

> LPeg version 0.10 is out:
>
>   http://www.inf.puc-rio.br/~roberto/lpeg/
>
> * Changes from version 0.9 to 0.10
>   -------------------------------
>   + backtrack stack has configurable size
>   + better error messages
>   + Notation for non-terminals in 're' back to A instead o <A>
>   + experimental look-behind pattern
>   + support for external extensions
>   + works with Lua 5.2
>   + consumes less C stack

Cool! I'm particularly pleased that most of my patch is now
unnecessary.

Could you please re-generate the tarball to unpack into an lpeg-0.10
subdirectory?

I see that the re module is now using a locale-dependent definition of
space for parsing grammars, which is opposite to the locale-independent
trend of Lua-5.2.

These are the extra operator overloads I like to use with lpeg.

   do
      local mt = getmetatable(lpeg.P(0))
      mt.__mod = lpeg.Cf
      mt.__concat = function (a,b)
         return a * lpeg.P{ b + 1 * lpeg.V(1) }
      end
   end

And this patch adds a similar search operator to the re syntax.

--- a/re.lua
+++ b/re.lua
@@ -159,6 +159,8 @@ local exp = m.P{ "Exp",
         * (#exp_follow + patt_error);
   Prefix = "&" * S * m.V"Prefix" / mt.__len
          + "!" * S * m.V"Prefix" / mt.__unm
+         + ".." * S * m.V"Prefix" /
+                   function (p) return m.P{ p + 1 * m.V(1) } end
          + m.V"Suffix";
   Suffix = m.Cf(m.V"Primary" * S *
           ( ( m.P"+" * m.Cc(1, mt.__pow)

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
HUMBER THAMES DOVER WIGHT PORTLAND: NORTH BACKING WEST OR NORTHWEST, 5 TO 7,
DECREASING 4 OR 5, OCCASIONALLY 6 LATER IN HUMBER AND THAMES. MODERATE OR
ROUGH. RAIN THEN FAIR. GOOD.