Blob Blame History Raw
From 8ab273b5314763f8f5ca41f49518b53f315dab0a Mon Sep 17 00:00:00 2001
From: Petr Machata <pmachata@gmail.com>
Date: Mon, 1 Jan 2018 23:51:54 +0100
Subject: [PATCH] libzwerg/op: Capture needs to reset its subop

When capture is done draining its subop for the current list instance,
it needs to des/con its subop's state. If the subop is an alt list,
after the draining it knows that there's nothing more to yield so it
won't. Capture needs to reset it, thereby signalling that it's safe to
pull from upstream again.

Signed-off-by: Petr Machata <pmachata@gmail.com>
---
 libzwerg/op.cc      |  4 +++-
 libzwerg/test-op.cc | 14 +++++++++++++-
 3 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/libzwerg/op.cc b/libzwerg/op.cc
index 43a02b6..9fc2d23 100644
--- a/libzwerg/op.cc
+++ b/libzwerg/op.cc
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2017 Petr Machata
+   Copyright (C) 2017, 2018 Petr Machata
    Copyright (C) 2014, 2015 Red Hat, Inc.
    This file is part of dwgrep.
 
@@ -566,6 +566,8 @@ op_capture::next (scon &sc) const
 	vv.push_back (stk2->pop ());
 
       stk->push (std::make_unique <value_seq> (std::move (vv), 0));
+      m_op->state_des (sc);
+      m_op->state_con (sc);
       return stk;
     }
 
diff --git a/libzwerg/test-op.cc b/libzwerg/test-op.cc
index a1cb94d..c5500ca 100644
--- a/libzwerg/test-op.cc
+++ b/libzwerg/test-op.cc
@@ -1,5 +1,5 @@
 /*
-   Copyright (C) 2017 Petr Machata
+   Copyright (C) 2017, 2018 Petr Machata
    Copyright (C) 2015 Red Hat, Inc.
    This file is part of dwgrep.
 
@@ -296,3 +296,15 @@ TEST_F (ZwTest, test_assert_block)
   auto yielded = run_query (*builtins, std::move (stk), "{} (drop {})*");
   ASSERT_EQ (2, yielded.size ());
 }
+
+TEST_F (ZwTest, test_various)
+{
+  for (auto const &entry: std::map <size_t, std::string> {
+	    {2, "(1, 2) drop [4, 5] [] ?ne"},
+	})
+    {
+      auto stk = std::make_unique <stack> ();
+      auto yielded = run_query (*builtins, std::move (stk), entry.second);
+      ASSERT_EQ (entry.first, yielded.size ());
+    }
+}
-- 
2.14.3