Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[not ready for review yet] Allow calc expressions when parsing numbers #7308

Closed
wants to merge 17 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Fix some calc parsing panics

  • Loading branch information
dzbarsky committed Aug 21, 2015
commit f2045bd8d12671fe0917809e1cee791920f1c8d4
@@ -504,13 +504,8 @@ pub mod specified {

match node_with_unit {
None => Ok(CalcAstNode::Value(CalcValueNode::Number(multiplier))),
Some(CalcValueNode::Sum(box sum)) =>
Ok(CalcAstNode::Add(CalcSumNode {
products: sum.products
.iter()
.map(|p| Calc::multiply_product(p, multiplier))
.collect()
})),
Some(CalcValueNode::Sum(box ref sum)) =>
Ok(CalcAstNode::Add(Calc::multiply_sum(sum, multiplier))),
Some(ref value) =>
Ok(CalcAstNode::Value(Calc::multiply_value(value, multiplier))),
}
@@ -525,11 +520,22 @@ pub mod specified {
}
}

fn multiply_sum(node: &CalcSumNode, multiplier: CSSFloat) -> CalcSumNode {
CalcSumNode {
products: node.products
.iter()
.map(|p| Calc::multiply_product(p, multiplier))
.collect()
}
}

fn multiply_value(node: &CalcValueNode, multiplier: CSSFloat) -> CalcValueNode {
println!("multiplying {:?} by {}", node, multiplier);
match node {
&CalcValueNode::Number(_) => unreachable!(),
&CalcValueNode::Number(num) => CalcValueNode::Number(num * multiplier),
&CalcValueNode::Percentage(p) => CalcValueNode::Percentage(p * multiplier),
&CalcValueNode::Sum(_) => unreachable!(),
&CalcValueNode::Sum(box ref sum) =>
CalcValueNode::Sum(box Calc::multiply_sum(sum, multiplier)),
&CalcValueNode::Length(l) => CalcValueNode::Length(l * multiplier),
}
}
@@ -544,6 +550,7 @@ pub mod specified {
CalcAstNode::Value(value) => simplified.push(value),
CalcAstNode::Add(sum) => {
for product in sum.products {
println!(" Matching product AST: {:?}", product);
assert!(product.values.len() == 1);
simplified.push(product.values[0].clone());
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.