Another example, testing rule priorities a bit

This commit is contained in:
Chris Fallin
2021-09-04 20:37:47 -07:00
parent bc91a4e5f6
commit b8e916a0ab
2 changed files with 29 additions and 5 deletions

View File

@@ -0,0 +1,19 @@
(type u32 (primitive u32))
(type A (enum
(A1 (x B) (y B))))
(type B (enum
(B1 (x u32))))
(decl A2B (A) B)
(rule 1
(A2B (A.A1 _ (B.B1 x)))
(B.B1 x))
(rule 1
(A2B (A.A1 (B.B1 x) _))
(B.B1 x))
(rule -1
(A2B (A.A1 _ _))
(B.B1 42))

View File

@@ -712,7 +712,11 @@ impl<'a> Codegen<'a> {
let mut body_ctx: BodyContext = Default::default();
body_ctx.expected_return_vals = 1;
let returned =
self.generate_body(code, /* depth = */ 0, trie, " ", &mut body_ctx)?;
if !returned {
writeln!(code, " return None;")?;
}
writeln!(code, "}}")?;
}
@@ -768,7 +772,11 @@ impl<'a> Codegen<'a> {
let mut body_ctx: BodyContext = Default::default();
body_ctx.expected_return_vals = ret_tuple_tys.len();
body_ctx.tuple_return = true;
let returned =
self.generate_body(code, /* depth = */ 0, trie, " ", &mut body_ctx)?;
if !returned {
writeln!(code, " return None;")?;
}
writeln!(code, "}}")?;
}
@@ -1092,9 +1100,6 @@ impl<'a> Codegen<'a> {
}
}
if !returned {
writeln!(code, "{}return None;", indent)?;
}
Ok(returned)
}
}