From b913eb2cf032b1d7934e2a8b485e4d71000ecd9e Mon Sep 17 00:00:00 2001 From: Mark Date: Mon, 31 Jul 2023 16:30:52 -0700 Subject: [PATCH] Comments --- src/parser/stage/treeify.rs | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/parser/stage/treeify.rs b/src/parser/stage/treeify.rs index e988a9a..0bd1a50 100644 --- a/src/parser/stage/treeify.rs +++ b/src/parser/stage/treeify.rs @@ -23,7 +23,7 @@ fn treeify_binary( Token::Operator(l, _) => l, _ => panic!() }; - return Err((*l, ParserError::Syntax)); + return Err((*l, ParserError::Syntax)); // left argument is empty } @@ -35,7 +35,7 @@ fn treeify_binary( Token::Operator(l, _) => l, _ => panic!() }; - return Err((*l, ParserError::Syntax)); + return Err((*l, ParserError::Syntax)); // Left argument is empty } }; @@ -47,7 +47,7 @@ fn treeify_binary( Token::Operator(l, _) => l, _ => panic!() }; - return Err((*l, ParserError::Syntax)); + return Err((*l, ParserError::Syntax)); // right argument is empty } }; @@ -57,7 +57,7 @@ fn treeify_binary( if let Token::Operator(l, s) = left { let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // Bad string let o = o.unwrap(); if { @@ -66,17 +66,14 @@ fn treeify_binary( } { return Ok(false); } else { - let tl = *this.get_line_location(); - return Err(( - LineLocation{pos: l.pos, len: tl.pos - l.pos + tl.len}, - ParserError::Syntax - )); + let tl = *this.get_line_location() + *l; + return Err((tl, ParserError::Syntax)); // left operator isn't valid } } if let Token::Operator(l, s) = right { let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // Bad string let o = o.unwrap(); if { @@ -86,7 +83,7 @@ fn treeify_binary( return Ok(false); } else { let tl = *this.get_line_location() + *l; - return Err((tl, ParserError::Syntax)); + return Err((tl, ParserError::Syntax)); // right operator isn't valid (two operators next to each other) } } @@ -95,7 +92,7 @@ fn treeify_binary( let this_op = { let Token::Operator(l, s) = this else {panic!()}; let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // bad operator string o.unwrap() }; @@ -103,14 +100,14 @@ fn treeify_binary( let left_op = if i > 1 { let Token::Operator(l, s) = &g_inner[i-2] else {panic!()}; let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // Bad operator string Some(o.unwrap()) } else { None }; let right_op = if i < g_inner.len()-2 { let Token::Operator(l, s) = &g_inner[i+2] else {panic!()}; let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // Bad operator string Some(o.unwrap()) } else { None }; @@ -175,7 +172,7 @@ fn treeify_unary( Token::Operator(l, _) => l, _ => panic!() }; - return Err((*l, ParserError::Syntax)); + return Err((*l, ParserError::Syntax)); // argument is missing } }; } else { @@ -187,7 +184,7 @@ fn treeify_unary( Token::Operator(l, _) => l, _ => panic!() }; - return Err((*l, ParserError::Syntax)); + return Err((*l, ParserError::Syntax)); // argument is missing } }; } @@ -204,6 +201,7 @@ fn treeify_unary( if prev.is_some() { if let Token::Operator(_,_) = prev.unwrap() { } else { + // Previous operator is invalid return Err(( *this.get_line_location(), ParserError::Syntax @@ -213,6 +211,7 @@ fn treeify_unary( if let Token::Operator(l, _) = next { let tl = *this.get_line_location() + *l; + // Argument is invalid return Err((tl, ParserError::Syntax)); } else { @@ -220,7 +219,7 @@ fn treeify_unary( let this_op = { let Token::Operator(l, s) = this else {panic!()}; let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // Bad string o.unwrap() }; @@ -229,14 +228,14 @@ fn treeify_unary( if i > 1 { let Token::Operator(l, s) = &g_inner[i-2] else {panic!()}; let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // Bad string Some(o.unwrap()) } else { None } } else { if i < g_inner.len()-2 { let Token::Operator(l, s) = &g_inner[i+2] else {panic!()}; let o = Operator::from_string(s); - if o.is_none() { return Err((*l, ParserError::Syntax)); } + if o.is_none() { return Err((*l, ParserError::Syntax)); } // Bad string Some(o.unwrap()) } else { None } };