hdl.dsl: further clarify error message for incorrect nesting.

Fixes #133.
This commit is contained in:
whitequark 2019-07-07 01:03:59 +00:00
parent cb8be4a1b0
commit da1f58b7ae
2 changed files with 12 additions and 4 deletions

View file

@ -133,8 +133,14 @@ class Module(_ModuleBuilderRoot, Elaboratable):
raise SyntaxError("{} is not permitted outside of {}"
.format(construct, context))
else:
raise SyntaxError("{} is not permitted directly inside of {}"
.format(construct, self._ctrl_context))
if self._ctrl_context == "Switch":
secondary_context = "Case"
if self._ctrl_context == "FSM":
secondary_context = "State"
raise SyntaxError("{} is not permitted directly inside of {}; it is permitted "
"inside of {} {}"
.format(construct, self._ctrl_context,
self._ctrl_context, secondary_context))
def _get_ctrl(self, name):
if self._ctrl_stack:

View file

@ -345,7 +345,8 @@ class DSLTestCase(FHDLTestCase):
m = Module()
with m.Switch(self.s1):
with self.assertRaises(SyntaxError,
msg="If is not permitted directly inside of Switch"):
msg="If is not permitted directly inside of Switch; "
"it is permitted inside of Switch Case"):
with m.If(self.s2):
pass
@ -486,7 +487,8 @@ class DSLTestCase(FHDLTestCase):
with m.State("FOO"):
pass
with self.assertRaises(SyntaxError,
msg="If is not permitted directly inside of FSM"):
msg="If is not permitted directly inside of FSM; "
"it is permitted inside of FSM State"):
with m.If(self.s2):
pass