Adds Continue macro to MuranoPL
Continue is a complimentary operator to Break Change-Id: I85892d6e0fa373d31754e6830ce44f9c528f79d4 Implements: blueprint muranopl-continue-operator
This commit is contained in:
parent
9a39c31cb9
commit
aaa2a41742
@ -30,6 +30,10 @@ class BreakException(InternalFlowException):
|
||||
pass
|
||||
|
||||
|
||||
class ContinueException(InternalFlowException):
|
||||
pass
|
||||
|
||||
|
||||
class DslInvalidOperationError(Exception):
|
||||
pass
|
||||
|
||||
|
@ -61,9 +61,12 @@ class MethodBlock(CodeBlock):
|
||||
super(MethodBlock, self).execute(new_context, murano_class)
|
||||
except exceptions.ReturnException as e:
|
||||
return e.value
|
||||
except exceptions.BreakException as e:
|
||||
except exceptions.BreakException:
|
||||
raise exceptions.DslInvalidOperationError(
|
||||
'Break cannot be used on method level')
|
||||
except exceptions.ContinueException:
|
||||
raise exceptions.DslInvalidOperationError(
|
||||
'Continue cannot be used on method level')
|
||||
else:
|
||||
return None
|
||||
|
||||
@ -86,6 +89,15 @@ class BreakMacro(expressions.DslExpression):
|
||||
raise exceptions.BreakException()
|
||||
|
||||
|
||||
class ContinueMacro(expressions.DslExpression):
|
||||
def __init__(self, Continue):
|
||||
if Continue:
|
||||
raise exceptions.DslSyntaxError('Continue cannot have value')
|
||||
|
||||
def execute(self, context, murano_class):
|
||||
raise exceptions.ContinueException()
|
||||
|
||||
|
||||
class ParallelMacro(CodeBlock):
|
||||
def __init__(self, Parallel, Limit=None):
|
||||
super(ParallelMacro, self).__init__(Parallel)
|
||||
@ -144,6 +156,8 @@ class WhileDoMacro(expressions.DslExpression):
|
||||
break
|
||||
except exceptions.BreakException:
|
||||
break
|
||||
except exceptions.ContinueException:
|
||||
continue
|
||||
|
||||
|
||||
class ForMacro(expressions.DslExpression):
|
||||
@ -163,6 +177,8 @@ class ForMacro(expressions.DslExpression):
|
||||
self._code.execute(context, murano_class)
|
||||
except exceptions.BreakException:
|
||||
break
|
||||
except exceptions.ContinueException:
|
||||
continue
|
||||
|
||||
|
||||
class RepeatMacro(expressions.DslExpression):
|
||||
@ -180,6 +196,8 @@ class RepeatMacro(expressions.DslExpression):
|
||||
self._code.execute(context, murano_class)
|
||||
except exceptions.BreakException:
|
||||
break
|
||||
except exceptions.ContinueException:
|
||||
continue
|
||||
|
||||
|
||||
class MatchMacro(expressions.DslExpression):
|
||||
@ -242,6 +260,7 @@ def register():
|
||||
expressions.register_macro(DoMacro)
|
||||
expressions.register_macro(ReturnMacro)
|
||||
expressions.register_macro(BreakMacro)
|
||||
expressions.register_macro(ContinueMacro)
|
||||
expressions.register_macro(ParallelMacro)
|
||||
expressions.register_macro(IfMacro)
|
||||
expressions.register_macro(WhileDoMacro)
|
||||
|
@ -68,6 +68,18 @@ Methods:
|
||||
- trace(method_break)
|
||||
- Break:
|
||||
|
||||
testContinue:
|
||||
Body:
|
||||
- For: t
|
||||
In: range(0, 7)
|
||||
Do:
|
||||
- If: $t >= 3 and $t < 5
|
||||
Then:
|
||||
- Continue:
|
||||
- trace($t)
|
||||
- trace(method_continue)
|
||||
- Continue:
|
||||
|
||||
testMatch:
|
||||
Arguments:
|
||||
arg:
|
||||
|
@ -49,6 +49,11 @@ class TestMacros(test_case.DslTestCase):
|
||||
self._runner.testBreak)
|
||||
self.assertEqual([0, 1, 2, 'breaking', 'method_break'], self.traces)
|
||||
|
||||
def test_continue(self):
|
||||
self.assertRaises(exceptions.DslInvalidOperationError,
|
||||
self._runner.testContinue)
|
||||
self.assertEqual([0, 1, 2, 5, 6, 'method_continue'], self.traces)
|
||||
|
||||
def test_match(self):
|
||||
self.assertEqual('y', self._runner.testMatch(1))
|
||||
self.assertEqual('x', self._runner.testMatch(2))
|
||||
|
Loading…
x
Reference in New Issue
Block a user