From e051077a26cdf1af989c01587c1fa93c4ecacd37 Mon Sep 17 00:00:00 2001 From: Justin Viiret Date: Wed, 6 Jan 2016 11:45:31 +1100 Subject: [PATCH] Remove "dot" entries from leftfix lookarounds Note that we have to be careful to leave the first lookaround entry in place, if it's a dot. This should eventually be done with a program instruction. --- src/rose/rose_build_lookaround.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/rose/rose_build_lookaround.cpp b/src/rose/rose_build_lookaround.cpp index 02843fee..54c01e08 100644 --- a/src/rose/rose_build_lookaround.cpp +++ b/src/rose/rose_build_lookaround.cpp @@ -582,6 +582,30 @@ bool getTransientPrefixReach(const NGHolder &g, u32 lag, return true; } +static +void normaliseLeftfix(map &look) { + // We can erase entries where the reach is "all characters", except for the + // very first one -- this might be required to establish a minimum bound on + // the literal's match offset. + + // TODO: It would be cleaner to use a literal program instruction to check + // the minimum bound explicitly. + + if (look.empty()) { + return; + } + + const auto earliest = begin(look)->first; + + vector dead; + for (const auto &m : look) { + if (m.second.all() && m.first != earliest) { + dead.push_back(m.first); + } + } + erase_all(&look, dead); +} + bool makeLeftfixLookaround(const RoseBuildImpl &build, const RoseVertex v, vector &lookaround) { lookaround.clear(); @@ -606,6 +630,7 @@ bool makeLeftfixLookaround(const RoseBuildImpl &build, const RoseVertex v, } trimLiterals(build, v, look); + normaliseLeftfix(look); if (look.size() > MAX_LOOKAROUND_ENTRIES) { DEBUG_PRINTF("lookaround too big (%zu entries)\n", look.size());