Skip to content
Snippets Groups Projects
Commit ab1b3d63 authored by Adam Radziszewski's avatar Adam Radziszewski
Browse files

iter semantics: always sets iter var to nowhere if False is returned

parent aa21c93f
No related merge requests found
...@@ -25,11 +25,8 @@ std::ostream& Iteration::write_to(std::ostream& os) const ...@@ -25,11 +25,8 @@ std::ostream& Iteration::write_to(std::ostream& os) const
Iteration::BaseRetValPtr Iteration::apply_internal(const FunExecContext& context) const Iteration::BaseRetValPtr Iteration::apply_internal(const FunExecContext& context) const
{ {
// Set iteration variable to Nowhere
// Should be overridden if succeeded
const boost::shared_ptr<Position>& iter_var = const boost::shared_ptr<Position>& iter_var =
context.variables()->get_fast(iter_var_acc_); context.variables()->get_fast(iter_var_acc_);
iter_var->set_value(Position::Nowhere);
const SentenceContext& sc = context.sentence_context(); const SentenceContext& sc = context.sentence_context();
// Proceed only if range extremes are not "nowhere". // Proceed only if range extremes are not "nowhere".
const boost::shared_ptr<const Position>& range_left = const boost::shared_ptr<const Position>& range_left =
...@@ -48,7 +45,7 @@ Iteration::BaseRetValPtr Iteration::apply_internal(const FunExecContext& context ...@@ -48,7 +45,7 @@ Iteration::BaseRetValPtr Iteration::apply_internal(const FunExecContext& context
} }
} }
} }
// Failure. Make sure iteration variable points Nowhere and return False // Failure. Set iteration variable to Nowhere and return False
iter_var->set_value(Position::Nowhere); iter_var->set_value(Position::Nowhere);
return Predicate::False(context); return Predicate::False(context);
} }
......
...@@ -36,3 +36,58 @@ only(1, 0, $It, False) ...@@ -36,3 +36,58 @@ only(1, 0, $It, False)
True True
It=nowhere It=nowhere
--- ---
and(setvar($It,2), rlook(0, 1, $It, True))
True
It=0
---
and(setvar($It,2), llook(1, 0, $It, True))
True
It=1
---
and(setvar($It,2), rlook(1, 0, $It, True))
False
It=nowhere
---
and(setvar($It,2), llook(0, 1, $It, True))
False
It=nowhere
---
and(setvar($It,2), only(0, 1, $It, True))
True
It=1
---
and(setvar($It,2), only(1, 0, $It, True))
True
It=2
---
and(setvar($It,2), only(1, 0, $It, False))
True
It=2
---
and(setvar($It,2), only(0, 1, $It, False))
False
It=nowhere
---
and(setvar($It,6), atleast(0, 3, $It, inside($It), 2))
True
It=1
---
and(setvar($It,6), atleast(3, 0, $It, inside($It), 2))
False
It=nowhere
---
and(setvar($It,6), atleast(0, 3, $It, inside($It), 7))
False
It=nowhere
---
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment