Skip to content

Commit

Permalink
Change parameter order
Browse files Browse the repository at this point in the history
  • Loading branch information
cenodis committed Aug 15, 2021
1 parent 4dc5f7c commit b504d39
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
20 changes: 10 additions & 10 deletions src/precedence/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ where
///
/// Intended for use with [precedence].
/// # Arguments
/// * `parser` The parser to apply.
/// * `precedence` The precedence of the operator.
/// * `parser` The parser to apply.
pub fn unary_op<I, O, E, P, Q>(
mut parser: P,
precedence: Q,
mut parser: P,
) -> impl FnMut(I) -> IResult<I, Unary<O, Q>, E>
where
P: Parser<I, O, E>,
Expand All @@ -97,13 +97,13 @@ where
///
/// Intended for use with [precedence].
/// # Arguments
/// * `parser` The parser to apply.
/// * `precedence` The precedence of the operator.
/// * `assoc` The associativity of the operator.
/// * `parser` The parser to apply.
pub fn binary_op<I, O, E, P, Q>(
mut parser: P,
precedence: Q,
assoc: Assoc,
mut parser: P,
) -> impl FnMut(I) -> IResult<I, Binary<O, Q>, E>
where
P: Parser<I, O, E>,
Expand Down Expand Up @@ -159,13 +159,13 @@ where
///
/// fn parser(i: &str) -> IResult<&str, i64> {
/// precedence(
/// unary_op(tag("-"), 1),
/// unary_op(verify(tag(""), |_: &str| false), 2), //TODO, replace with a "fail" parser?
/// unary_op(1, tag("-")),
/// unary_op(2, verify(tag(""), |_: &str| false)), //TODO, replace with a "fail" parser?
/// alt((
/// binary_op(tag("*"), 3, Assoc::Left),
/// binary_op(tag("/"), 3, Assoc::Left),
/// binary_op(tag("+"), 4, Assoc::Left),
/// binary_op(tag("-"), 4, Assoc::Left),
/// binary_op(3, Assoc::Left, tag("*")),
/// binary_op(3, Assoc::Left, tag("/")),
/// binary_op(4, Assoc::Left, tag("+")),
/// binary_op(4, Assoc::Left, tag("-")),
/// )),
/// alt((
/// map(digit1, |s: &str| s.parse::<i64>().unwrap()),
Expand Down
12 changes: 6 additions & 6 deletions src/precedence/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ use crate::precedence::precedence;
#[cfg(feature = "alloc")]
fn parser(i: &str) -> IResult<&str, i64> {
precedence(
unary_op(tag("-"), 1),
unary_op(verify(tag(""), |_: &str| false), 2), //TODO, fail parser
unary_op(1, tag("-")),
unary_op(2, verify(tag(""), |_: &str| false)), //TODO, fail parser
alt((
binary_op(tag("*"), 3, Assoc::Left),
binary_op(tag("/"), 3, Assoc::Left),
binary_op(tag("+"), 4, Assoc::Left),
binary_op(tag("-"), 4, Assoc::Left),
binary_op(3, Assoc::Left, tag("*")),
binary_op(3, Assoc::Left, tag("/")),
binary_op(4, Assoc::Left, tag("+")),
binary_op(4, Assoc::Left, tag("-")),
)),
alt((
map(digit1, |s: &str| s.parse::<i64>().unwrap()),
Expand Down

0 comments on commit b504d39

Please sign in to comment.