hdl.dsl: further clarify error message for incorrect nesting.
authorwhitequark <cz@m-labs.hk>
Sun, 7 Jul 2019 01:03:59 +0000 (01:03 +0000)
committerwhitequark <cz@m-labs.hk>
Sun, 7 Jul 2019 01:03:59 +0000 (01:03 +0000)
Fixes #133.

nmigen/hdl/dsl.py
nmigen/test/test_hdl_dsl.py

index a2cec0b45d3df1d03582267fdc3ef6543d36f4d0..43da83a49aa2c0663f4c962ce90c622492b7ab97 100644 (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:
index e01b083b22cbdc50ff451c79440761bd205bd001..43f83d28813cd88065074dfbd2b7060d9c1b8122 100644 (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