From 91745af1499c2dbd5969970b9b4ea7773cead51b Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 29 Sep 2023 05:52:56 -0400 Subject: [PATCH] Implement control flow --- src/interface.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/interface.rs b/src/interface.rs index 5f77d48..d59a4d0 100644 --- a/src/interface.rs +++ b/src/interface.rs @@ -189,7 +189,11 @@ enum Expression { impl Expression { fn new(node: Node, source: &str) -> Result { - let child = node.child(0).unwrap().child(0).unwrap(); + let mut child = node.child(0).unwrap(); + + if child.kind() == "expression" { + child = child.child(0).unwrap(); + } if child.kind() == "identifier" { let byte_range = child.byte_range(); @@ -297,9 +301,9 @@ impl ControlFlow { fn new(node: Node, source: &str) -> Result { let second_child = node.child(1).unwrap(); let fourth_child = node.child(3).unwrap(); - let fifth_child = node.child(4); - println!("{second_child:?} {fourth_child:?} {fifth_child:?}"); - let else_statement = if let Some(child) = fifth_child { + let sixth_child = node.child(5); + println!("{second_child:?} {fourth_child:?} {sixth_child:?}"); + let else_statement = if let Some(child) = sixth_child { Some(Statement::new(child, source)?) } else { None