[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A C++ Pattern Matching Library based on lstrlib.c
- From: steve donovan <steve.j.donovan@...>
- Date: Sun, 31 May 2015 17:25:56 +0200
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