diff options
author | Shmuel Zeigerman <solomuz0@gmail.com> | 2014-10-30 20:10:02 +0200 |
---|---|---|
committer | Shmuel Zeigerman <solomuz0@gmail.com> | 2014-10-30 20:10:02 +0200 |
commit | 1512d3999ec87650d77011f0ccf0eef2fbc478d6 (patch) | |
tree | a73b906b9bbae4eea77d2a513642aa06653e86f6 | |
parent | 150c251be57c4e569da0f48bf6b01fbca97179fe (diff) | |
download | lrexlib-1512d3999ec87650d77011f0ccf0eef2fbc478d6.tar.gz |
Added method "fullinfo" to PCRE binding.
-rw-r--r-- | doc/manual.txt | 15 | ||||
-rw-r--r-- | src/pcre/lpcre.c | 38 | ||||
-rw-r--r-- | test/pcre_sets.lua | 7 |
3 files changed, 60 insertions, 0 deletions
diff --git a/doc/manual.txt b/doc/manual.txt index 50397b2..5fec66a 100644 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -565,6 +565,21 @@ userdata obtained from a call to maketables_. The default value, used when the parameter is not supplied or ``nil``, is the built-in PCRE set of character tables. +------------------------------------------------------------ + +fullinfo +-------- + +[See *pcre_fullinfo* in the PCRE docs.] + +:funcdef:`r:fullinfo ()` + +This function returns a table containing information about the compiled pattern. +The keys are strings formed in the following way: +``PCRE_INFO_CAPTURECOUNT`` -> ``"CAPTURECOUNT"``. The values are numbers. + +------------------------------------------------------------ + dfa_exec -------- diff --git a/src/pcre/lpcre.c b/src/pcre/lpcre.c index 8ef0803..5a5c98d 100644 --- a/src/pcre/lpcre.c +++ b/src/pcre/lpcre.c @@ -5,6 +5,7 @@ #include <string.h> #include <locale.h> #include <ctype.h> +#include <stdint.h> #include <pcre.h> #include "lua.h" @@ -351,6 +352,42 @@ static int Lpcre_version (lua_State *L) { return 1; } +#define SET_INFO_FIELD(L,ud,what,name,valtype) { \ + valtype val; \ + if (0 == pcre_fullinfo (ud->pr, ud->extra, what, &val)) { \ + lua_pushnumber (L, val); \ + lua_setfield (L, -2, name); \ + } \ +} + +static int Lpcre_fullinfo (lua_State *L) { + TPcre *ud = check_ud (L); + lua_newtable(L); + + SET_INFO_FIELD (L, ud, PCRE_INFO_BACKREFMAX, "BACKREFMAX", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_CAPTURECOUNT, "CAPTURECOUNT", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_FIRSTBYTE, "FIRSTBYTE", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_HASCRORLF, "HASCRORLF", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_JCHANGED, "JCHANGED", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_JIT, "JIT", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_JITSIZE, "JITSIZE", size_t); + SET_INFO_FIELD (L, ud, PCRE_INFO_MATCH_EMPTY, "MATCH_EMPTY", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_MATCHLIMIT, "MATCHLIMIT", uint32_t) + SET_INFO_FIELD (L, ud, PCRE_INFO_MAXLOOKBEHIND, "MAXLOOKBEHIND", int) /* int ? */ + SET_INFO_FIELD (L, ud, PCRE_INFO_MINLENGTH, "MINLENGTH", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_OKPARTIAL, "OKPARTIAL", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_OPTIONS, "OPTIONS", unsigned long) + SET_INFO_FIELD (L, ud, PCRE_INFO_RECURSIONLIMIT, "RECURSIONLIMIT", uint32_t) + SET_INFO_FIELD (L, ud, PCRE_INFO_SIZE, "SIZE", size_t) + SET_INFO_FIELD (L, ud, PCRE_INFO_STUDYSIZE, "STUDYSIZE", size_t) + SET_INFO_FIELD (L, ud, PCRE_INFO_FIRSTCHARACTERFLAGS, "FIRSTCHARACTERFLAGS", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_FIRSTCHARACTER, "FIRSTCHARACTER", uint32_t) + SET_INFO_FIELD (L, ud, PCRE_INFO_REQUIREDCHARFLAGS, "REQUIREDCHARFLAGS", int) + SET_INFO_FIELD (L, ud, PCRE_INFO_REQUIREDCHAR, "REQUIREDCHAR", uint32_t) + + return 1; +} + static const luaL_Reg chartables_meta[] = { { "__gc", chartables_gc }, { "__tostring", chartables_tostring }, @@ -365,6 +402,7 @@ static const luaL_Reg r_methods[] = { #if PCRE_MAJOR >= 6 { "dfa_exec", Lpcre_dfa_exec }, #endif + { "fullinfo", Lpcre_fullinfo }, { "__gc", Lpcre_gc }, { "__tostring", Lpcre_tostring }, { NULL, NULL } diff --git a/test/pcre_sets.lua b/test/pcre_sets.lua index b02df78..cf81f42 100644 --- a/test/pcre_sets.lua +++ b/test/pcre_sets.lua @@ -160,6 +160,12 @@ local function set_m_dfa_exec (lib, flg) } end +local function set_m_fullinfo (lib, flg) + local r = lib.new("(foo)(bar)") + local info = r:fullinfo() + assert(info.CAPTURECOUNT == 2) +end + return function (libname) local lib = require (libname) local flags = lib.flags () @@ -170,6 +176,7 @@ return function (libname) set_f_split (lib, flags), set_m_exec (lib, flags), set_m_tfind (lib, flags), + set_m_fullinfo (lib, flags), } if flags.MAJOR >= 4 then table.insert (sets, set_named_subpatterns (lib, flags)) |