pull/2/head
Mark 2023-07-31 16:30:52 -07:00
parent 97b64e6bef
commit b913eb2cf0
Signed by: Mark
GPG Key ID: AD62BB059C2AAEE4
1 changed files with 18 additions and 19 deletions

View File

@ -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 }
};