From 839f1018295cd1bb807e194cae0407dbb984ca6a Mon Sep 17 00:00:00 2001 From: Connor Skees Date: Wed, 14 Jul 2021 21:19:18 -0400 Subject: [PATCH] emit comments inside `@if` rule --- src/parse/control_flow.rs | 5 +++-- tests/if.rs | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/src/parse/control_flow.rs b/src/parse/control_flow.rs index 90d3eeb..a228fb4 100644 --- a/src/parse/control_flow.rs +++ b/src/parse/control_flow.rs @@ -29,11 +29,10 @@ impl<'a> Parser<'a> { return Err(("expected \"}\".", self.span_before).into()); } - self.whitespace_or_comment(); - if init_cond.is_true() { self.scopes.enter_new_scope(); found_true = true; + body = Parser { toks: self.toks, map: self.map, @@ -53,6 +52,7 @@ impl<'a> Parser<'a> { module_config: self.module_config, } .parse_stmt()?; + self.scopes.exit_scope(); } else { self.throw_away_until_closing_curly_brace()?; @@ -108,6 +108,7 @@ impl<'a> Parser<'a> { module_config: self.module_config, } .parse_stmt()?; + self.scopes.exit_scope(); } else { self.throw_away_until_closing_curly_brace()?; diff --git a/tests/if.rs b/tests/if.rs index 162d314..1d0bd07 100644 --- a/tests/if.rs +++ b/tests/if.rs @@ -184,6 +184,33 @@ test!( }", "" ); +test!( + comment_inside_if_body, + "@if true { + /* a */ + }", + "/* a */\n" +); +test!( + comment_inside_if_else_body, + "@if false { + /* a */ + } @else if true { + /* b */ + }", + "/* b */\n" +); +test!( + comment_inside_else_body, + "@if false { + /* a */ + } @else if false { + /* b */ + } @else { + /* c */ + }", + "/* c */\n" +); error!( nothing_after_escape, "@if \\", "Error: Expected expression."