lua-users home
lua-l archive

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


> -----Original Message-----
> From: lua-l-bounces@lists.lua.org [mailto:lua-l-bounces@lists.lua.org] On
> Behalf Of steve donovan
> Sent: zondag 31 mei 2015 17:26
> To: Lua mailing list
> Subject: A C++ Pattern Matching Library based on lstrlib.c
> 
> I'll always be a admirer of the Lua pattern matching library, and
> started thinking about how one could design a C++ library that
> provided a similar interface.  Initially I was wrapping POSIX regexps,
> but with a twist: the ugly '\\' can be written as '%' and nasties like
> [[:alpha:]] can be written as '%a'. (This is a surface transformation
> and of course the semantics remains unaltered.)  During my experiments
> I found that the GNU regex implementation is pretty bad at dealing
> with large chunks of text (my test corpus was _The Adventures of
> Sherlock Holmes_ from the Gutenberg project.). So I've extracted the
> pattern matcher from lstrlib.c, and made an alternative wrapper for
> that as well.
> 
> So, the relevance here is: first, can we get a fluid Lua-like
> interface, and what adjustments need to be made? Second, re-using
> parts of Lua can be fun! [1] is the practical result and [2] is the
> discussion.
> 
> Rxp words("%a+",Rx::lua);  // simple Lua-style regexps
>  for (auto M:  words.gmatch(text)) {
>      if (M[0].size() > 6)
>          cout << M[0] << "\n";
>  }
> 
> ;)
> 
> steve d.
> 
> [1] https://github.com/stevedonovan/rx-cpp
> [2] http://steved-imaginaryreal.blogspot.com/2015/05/what-can-c-libraries-
> learn-from-lua.html


Reminds me of some code someone posted a while (1 or 2 years??) ago, creating a C string library based on a Lua state doing the actual work.

(did a quick search, but failed to find it in the archives)

Thijs