From 573df02ba60c9ac0cdccb421f34bca822cbde98e Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 14 Dec 2021 23:16:19 +0100 Subject: [PATCH] Fixed T-Dark blocks in blocks --- ablescript/src/parser.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/ablescript/src/parser.rs b/ablescript/src/parser.rs index 19c3926..6f7ebb6 100644 --- a/ablescript/src/parser.rs +++ b/ablescript/src/parser.rs @@ -37,12 +37,7 @@ impl<'source> Parser<'source> { Token::Comment => continue, // T-Dark block (replace `lang` with `script`) - Token::TDark => { - self.tdark = true; - let mut block = self.get_block()?; - ast.append(&mut block.block); - self.tdark = false; - } + Token::TDark => ast.extend(self.tdark_flow()?.block), token => ast.push(self.parse(token)?), } } @@ -329,12 +324,21 @@ impl<'source> Parser<'source> { loop { match self.checked_next()? { Token::RightCurly => break, + Token::TDark => block.extend(self.tdark_flow()?.block), t => block.push(self.parse(t)?), } } Ok(Block { block }) } + /// Parse T-Dark block + fn tdark_flow(&mut self) -> Result { + self.tdark = true; + let block = self.get_block(); + self.tdark = false; + block + } + /// If Statement parser gets any kind of value (Identifier or Literal) /// It cannot parse it as it do not parse expressions. Instead of it it /// will parse it to function call or print statement.