fix: flawed function parsing
enumerating after filtering made the index unusable
This commit is contained in:
parent
2ca3abf42f
commit
a88ec153ce
2 changed files with 8 additions and 9 deletions
|
|
@ -31,12 +31,11 @@ fn collapse_toplevel(nodes: &mut Vec<Node>, mut end: usize) {
|
|||
|
||||
while let Some((index, variant)) = nodes[start..end]
|
||||
.iter()
|
||||
.filter_map(|n| match n {
|
||||
Node::Function(f) => Some(f),
|
||||
.enumerate()
|
||||
.filter_map(|(i, n)| match n {
|
||||
Node::Function(f) => Some((i, *f)),
|
||||
_ => None,
|
||||
})
|
||||
.cloned()
|
||||
.enumerate()
|
||||
.next()
|
||||
{
|
||||
match &mut nodes[start..end][index + 1] {
|
||||
|
|
@ -50,7 +49,7 @@ fn collapse_toplevel(nodes: &mut Vec<Node>, mut end: usize) {
|
|||
Function::Secant => n.sec_mut(),
|
||||
Function::CoSecant => n.csc_mut(),
|
||||
},
|
||||
_ => panic!("function is missing an argument"),
|
||||
n => panic!("function is missing an argument, got: {n:?}"),
|
||||
};
|
||||
|
||||
nodes.remove(start + index);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ mod tests;
|
|||
|
||||
pub const PREC: u32 = 512;
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq)]
|
||||
#[derive(Debug, Default, Clone, PartialEq)]
|
||||
pub struct Nodes(Vec<Node>);
|
||||
impl AsRef<[Node]> for Nodes {
|
||||
fn as_ref(&self) -> &[Node] {
|
||||
|
|
@ -19,7 +19,7 @@ impl AsRef<[Node]> for Nodes {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
enum Node {
|
||||
Function(Function),
|
||||
ParenthesisStart,
|
||||
|
|
@ -28,7 +28,7 @@ enum Node {
|
|||
Operator(Operator),
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
#[derive(Debug, Default, Copy, Clone, PartialEq)]
|
||||
enum Operator {
|
||||
Plus,
|
||||
Minus,
|
||||
|
|
@ -38,7 +38,7 @@ enum Operator {
|
|||
Exp,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
#[derive(Debug, Copy, Clone, PartialEq)]
|
||||
enum Function {
|
||||
Sine,
|
||||
ArcSine,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue