Skip to content

Instantly share code, notes, and snippets.

@vadixidav
Created October 22, 2017 22:16
Show Gist options
  • Save vadixidav/a28d96fe7a02efa3f58ff5ae5f469c2f to your computer and use it in GitHub Desktop.
Save vadixidav/a28d96fe7a02efa3f58ff5ae5f469c2f to your computer and use it in GitHub Desktop.
fn fold_op<F: Fn(f64, f64)>(input: &[u8], init: f64, f: F) -> IResult<&[u8], f64> {
fold_many0!(ws!(alt!(apply!(list) | apply!(f64::from_str))), init, f)
}
named!(list<f64>, delimited!(tag!("("), ws!(alt!(
proceed!(tag!("+"), apply!(fop, 0.0, |acc, item| acc + item))
)), tag!(")")));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment