Fix control flow and reintroduce the semicolon parser
This commit is contained in:
parent
a5d2e7d869
commit
63312cf08a
@ -1437,7 +1437,10 @@ impl<'src> Compiler<'src> {
|
||||
|
||||
let if_block_end = self.instructions.len();
|
||||
let mut if_block_distance = if_block_end - if_block_start;
|
||||
let if_block_type = self.get_last_instruction_type();
|
||||
|
||||
let (if_block_last_instruction, if_block_type, _) = self.instructions.last().unwrap();
|
||||
let if_block_type = if_block_type.clone();
|
||||
let if_block_last_instruction_destination = if_block_last_instruction.a_field();
|
||||
|
||||
if let Token::Else = self.current_token {
|
||||
self.advance()?;
|
||||
@ -1459,9 +1462,12 @@ impl<'src> Compiler<'src> {
|
||||
|
||||
let else_block_end = self.instructions.len();
|
||||
let else_block_distance = else_block_end - if_block_end;
|
||||
let else_block_type = self.get_last_instruction_type();
|
||||
let (else_block_last_instruction, else_block_type, _) =
|
||||
self.instructions.last_mut().unwrap();
|
||||
|
||||
if let Err(conflict) = if_block_type.check(&else_block_type) {
|
||||
else_block_last_instruction.set_a_field(if_block_last_instruction_destination);
|
||||
|
||||
if let Err(conflict) = if_block_type.check(else_block_type) {
|
||||
return Err(CompileError::IfElseBranchMismatch {
|
||||
conflict,
|
||||
position: Span(if_block_start_position.0, self.current_position.1),
|
||||
@ -2035,6 +2041,16 @@ impl<'src> Compiler<'src> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn parse_semicolon(&mut self) -> Result<(), CompileError> {
|
||||
let (_, last_instruction_type, _) = self.instructions.last_mut().unwrap();
|
||||
|
||||
*last_instruction_type = Type::None;
|
||||
|
||||
self.advance()?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn expect_expression(&mut self) -> Result<(), CompileError> {
|
||||
Err(CompileError::ExpectedExpression {
|
||||
found: self.current_token.to_owned(),
|
||||
|
@ -237,7 +237,7 @@ impl From<&Token<'_>> for ParseRule<'_> {
|
||||
precedence: Precedence::None,
|
||||
},
|
||||
Token::Semicolon => ParseRule {
|
||||
prefix: None,
|
||||
prefix: Some(Compiler::parse_semicolon),
|
||||
infix: None,
|
||||
precedence: Precedence::None,
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user