]> granicus.if.org Git - re2c/commitdiff
libre2c: added GOR1 option for lazy disambiguation algorithm.
authorUlya Trofimovich <skvadrik@gmail.com>
Sat, 18 May 2019 18:07:57 +0000 (19:07 +0100)
committerUlya Trofimovich <skvadrik@gmail.com>
Sat, 18 May 2019 18:20:17 +0000 (19:20 +0100)
lib/regexec_nfa_posix_trie.cc
lib/test.cc

index 378d615fdff13d893c9193cacdd94a16fb91c9a4..8e6d32aee62db75245631fcf509eb2ac51e7190a 100644 (file)
 
 
 namespace re2c {
+
+// specialization that doesn't sort initial closure like Okui-Suzuki
+// (there is no cheap way to sort it in the lazy-disambiguation algorithm)
+template<> void init_gor1<libre2c::pzsimctx_t>(libre2c::pzsimctx_t &ctx);
+
 namespace libre2c {
 
+static inline void closure_posix(pzsimctx_t &ctx);
 static void make_step(pzsimctx_t &, uint32_t);
 static void make_final_step(pzsimctx_t &);
 
@@ -24,7 +30,7 @@ int regexec_nfa_posix_trie(const regex_t *preg, const char *string
     const conf_t c0(ctx.nfa.root, 0, HROOT);
     ctx.reach.push_back(c0);
     for (;;) {
-        closure_posix_gtop(ctx);
+        closure_posix(ctx);
         const uint32_t sym = static_cast<uint8_t>(*ctx.cursor++);
         if (ctx.state.empty() || sym == 0) break;
         make_step(ctx, sym);
@@ -34,6 +40,16 @@ int regexec_nfa_posix_trie(const regex_t *preg, const char *string
     return finalize(ctx, string, nmatch, pmatch);
 }
 
+void closure_posix(pzsimctx_t &ctx)
+{
+    if (ctx.flags & REG_GTOP) {
+        closure_posix_gtop(ctx);
+    }
+    else {
+        closure_posix_gor1(ctx);
+    }
+}
+
 void make_step(pzsimctx_t &ctx, uint32_t sym)
 {
     const confset_t &state = ctx.state;
@@ -46,7 +62,8 @@ void make_step(pzsimctx_t &ctx, uint32_t sym)
         nfa_state_t *s = i->state;
 
         s->clos = NOCLOS;
-        DASSERT(s->active == 0);
+        s->arcidx = 0;
+        DASSERT(s->status == GOR_NOPASS && s->active == 0);
 
         if (s->type == nfa_state_t::RAN) {
             for (const Range *r = s->ran.ran; r; r = r->next()) {
@@ -73,7 +90,8 @@ void make_final_step(pzsimctx_t &ctx)
         nfa_state_t *s = i->state;
 
         s->clos = NOCLOS;
-        DASSERT(s->active == 0);
+        s->arcidx = 0;
+        DASSERT(s->status == GOR_NOPASS && s->active == 0);
 
         if (s->type == nfa_state_t::FIN) {
             ctx.marker = ctx.cursor;
@@ -84,5 +102,15 @@ void make_final_step(pzsimctx_t &ctx)
 }
 
 } // namespace libre2c
+
+template<> void init_gor1<libre2c::pzsimctx_t>(libre2c::pzsimctx_t &ctx)
+{
+    ctx.state.clear();
+    libre2c::pzsimctx_t::cconfiter_t c = ctx.reach.begin(), e = ctx.reach.end();
+    for (; c != e; ++c) {
+        relax_gor1(ctx, *c);
+    }
+}
+
 } // namespace re2c
 
index 532d71ec47d290972624042880122a89fc1a79bd..c66336db9196c2412c714844f978e811a4beac68 100644 (file)
@@ -1068,6 +1068,7 @@ int main(int argc, char **argv)
     e |= test_all_posix(REG_NFA | REG_KUKLEWICZ | REG_GTOP);
 
     e |= test_all_posix(REG_NFA | REG_TRIE);
+    e |= test_all_posix(REG_NFA | REG_TRIE | REG_GTOP);
 
     e |= test_all_posix(REG_NFA | REG_SLOWPREC);