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:
@@ -30,6 +30,10 @@ class BreakException(InternalFlowException):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ContinueException(InternalFlowException):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class DslInvalidOperationError(Exception):
|
class DslInvalidOperationError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@@ -61,9 +61,12 @@ class MethodBlock(CodeBlock):
|
|||||||
super(MethodBlock, self).execute(new_context, murano_class)
|
super(MethodBlock, self).execute(new_context, murano_class)
|
||||||
except exceptions.ReturnException as e:
|
except exceptions.ReturnException as e:
|
||||||
return e.value
|
return e.value
|
||||||
except exceptions.BreakException as e:
|
except exceptions.BreakException:
|
||||||
raise exceptions.DslInvalidOperationError(
|
raise exceptions.DslInvalidOperationError(
|
||||||
'Break cannot be used on method level')
|
'Break cannot be used on method level')
|
||||||
|
except exceptions.ContinueException:
|
||||||
|
raise exceptions.DslInvalidOperationError(
|
||||||
|
'Continue cannot be used on method level')
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -86,6 +89,15 @@ class BreakMacro(expressions.DslExpression):
|
|||||||
raise exceptions.BreakException()
|
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):
|
class ParallelMacro(CodeBlock):
|
||||||
def __init__(self, Parallel, Limit=None):
|
def __init__(self, Parallel, Limit=None):
|
||||||
super(ParallelMacro, self).__init__(Parallel)
|
super(ParallelMacro, self).__init__(Parallel)
|
||||||
@@ -144,6 +156,8 @@ class WhileDoMacro(expressions.DslExpression):
|
|||||||
break
|
break
|
||||||
except exceptions.BreakException:
|
except exceptions.BreakException:
|
||||||
break
|
break
|
||||||
|
except exceptions.ContinueException:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
class ForMacro(expressions.DslExpression):
|
class ForMacro(expressions.DslExpression):
|
||||||
@@ -163,6 +177,8 @@ class ForMacro(expressions.DslExpression):
|
|||||||
self._code.execute(context, murano_class)
|
self._code.execute(context, murano_class)
|
||||||
except exceptions.BreakException:
|
except exceptions.BreakException:
|
||||||
break
|
break
|
||||||
|
except exceptions.ContinueException:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
class RepeatMacro(expressions.DslExpression):
|
class RepeatMacro(expressions.DslExpression):
|
||||||
@@ -180,6 +196,8 @@ class RepeatMacro(expressions.DslExpression):
|
|||||||
self._code.execute(context, murano_class)
|
self._code.execute(context, murano_class)
|
||||||
except exceptions.BreakException:
|
except exceptions.BreakException:
|
||||||
break
|
break
|
||||||
|
except exceptions.ContinueException:
|
||||||
|
continue
|
||||||
|
|
||||||
|
|
||||||
class MatchMacro(expressions.DslExpression):
|
class MatchMacro(expressions.DslExpression):
|
||||||
@@ -242,6 +260,7 @@ def register():
|
|||||||
expressions.register_macro(DoMacro)
|
expressions.register_macro(DoMacro)
|
||||||
expressions.register_macro(ReturnMacro)
|
expressions.register_macro(ReturnMacro)
|
||||||
expressions.register_macro(BreakMacro)
|
expressions.register_macro(BreakMacro)
|
||||||
|
expressions.register_macro(ContinueMacro)
|
||||||
expressions.register_macro(ParallelMacro)
|
expressions.register_macro(ParallelMacro)
|
||||||
expressions.register_macro(IfMacro)
|
expressions.register_macro(IfMacro)
|
||||||
expressions.register_macro(WhileDoMacro)
|
expressions.register_macro(WhileDoMacro)
|
||||||
|
@@ -68,6 +68,18 @@ Methods:
|
|||||||
- trace(method_break)
|
- trace(method_break)
|
||||||
- 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:
|
testMatch:
|
||||||
Arguments:
|
Arguments:
|
||||||
arg:
|
arg:
|
||||||
|
@@ -49,6 +49,11 @@ class TestMacros(test_case.DslTestCase):
|
|||||||
self._runner.testBreak)
|
self._runner.testBreak)
|
||||||
self.assertEqual([0, 1, 2, 'breaking', 'method_break'], self.traces)
|
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):
|
def test_match(self):
|
||||||
self.assertEqual('y', self._runner.testMatch(1))
|
self.assertEqual('y', self._runner.testMatch(1))
|
||||||
self.assertEqual('x', self._runner.testMatch(2))
|
self.assertEqual('x', self._runner.testMatch(2))
|
||||||
|
Reference in New Issue
Block a user