Add pmgen "fallthrough" statement
authorClifford Wolf <clifford@clifford.at>
Sat, 17 Aug 2019 09:29:37 +0000 (11:29 +0200)
committerClifford Wolf <clifford@clifford.at>
Sat, 17 Aug 2019 09:29:37 +0000 (11:29 +0200)
Signed-off-by: Clifford Wolf <clifford@clifford.at>
passes/pmgen/README.md
passes/pmgen/pmgen.py

index be908ef0b9e43ea21adc17a547f21cb9f4651325..5f6a8ab1b2e2ebf713fa4c870cd40d6a8291c212 100644 (file)
@@ -315,6 +315,9 @@ state variables used to pass arguments.
 
 Subpatterns cann be called recursively.
 
+If a `subpattern` statement is preceded by a `fallthrough` statement, this is
+equivalent to calling the subpattern at the end of the preceding block.
+
 Generate Blocks
 ---------------
 
index 6950a99c0aa7874927dae4862358ec60ae0debac..8401e1295e63da09cf1a540e144e3f22eaf728a3 100644 (file)
@@ -141,12 +141,23 @@ def process_pmgfile(f, filename):
 
         assert current_pattern is not None
 
-        if cmd == "subpattern":
+        if cmd == "fallthrough":
             block = dict()
-            block["type"] = "final"
-            block["pattern"] = (current_pattern, current_subpattern)
+            block["type"] = "fallthrough"
             blocks.append(block)
             line = line.split()
+            assert len(line) == 1
+            continue
+
+        if cmd == "subpattern":
+            if len(blocks) == 0 or blocks[-1]["type"] != "fallthrough":
+                block = dict()
+                block["type"] = "final"
+                block["pattern"] = (current_pattern, current_subpattern)
+                blocks.append(block)
+            elif len(blocks) and blocks[-1]["type"] == "fallthrough":
+                del blocks[-1]
+            line = line.split()
             assert len(line) == 2
             current_subpattern = line[1]
             subpattern_args[(current_pattern, current_subpattern)] = list()