Fix parsing precedence of left implication vs. less-than comparison
This commit is contained in:
parent
04e2d61583
commit
ba385868cb
@ -4,7 +4,7 @@ use nom::
|
||||
branch::alt,
|
||||
bytes::complete::tag,
|
||||
character::complete::multispace0,
|
||||
combinator::{cut, map, map_res},
|
||||
combinator::{cut, map, map_res, peek},
|
||||
multi::{many1, separated_list1},
|
||||
sequence::{delimited, pair, preceded, terminated, tuple},
|
||||
};
|
||||
@ -286,39 +286,43 @@ where
|
||||
delimited
|
||||
(
|
||||
multispace0,
|
||||
alt
|
||||
((
|
||||
map
|
||||
(
|
||||
tag("<="),
|
||||
|_| crate::ComparisonOperator::LessOrEqual,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag(">="),
|
||||
|_| crate::ComparisonOperator::GreaterOrEqual,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag(">"),
|
||||
|_| crate::ComparisonOperator::Greater,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag("<"),
|
||||
|_| crate::ComparisonOperator::Less,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag("!="),
|
||||
|_| crate::ComparisonOperator::NotEqual,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag("="),
|
||||
|_| crate::ComparisonOperator::Equal,
|
||||
),
|
||||
)),
|
||||
terminated
|
||||
(
|
||||
alt
|
||||
((
|
||||
map
|
||||
(
|
||||
tag("<="),
|
||||
|_| crate::ComparisonOperator::LessOrEqual,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag(">="),
|
||||
|_| crate::ComparisonOperator::GreaterOrEqual,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag("<"),
|
||||
|_| crate::ComparisonOperator::Less,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag(">"),
|
||||
|_| crate::ComparisonOperator::Greater,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag("!="),
|
||||
|_| crate::ComparisonOperator::NotEqual,
|
||||
),
|
||||
map
|
||||
(
|
||||
tag("="),
|
||||
|_| crate::ComparisonOperator::Equal,
|
||||
),
|
||||
)),
|
||||
peek(nom::combinator::not(tag("-"))),
|
||||
),
|
||||
multispace0,
|
||||
),
|
||||
|i| crate::parse::term(i, d, v),
|
||||
@ -381,13 +385,13 @@ where
|
||||
),
|
||||
map
|
||||
(
|
||||
|i| predicate(i, d, v),
|
||||
crate::Formula::Predicate,
|
||||
|i| compare(i, d, v),
|
||||
crate::Formula::Compare,
|
||||
),
|
||||
map
|
||||
(
|
||||
|i| compare(i, d, v),
|
||||
crate::Formula::Compare,
|
||||
|i| predicate(i, d, v),
|
||||
crate::Formula::Predicate,
|
||||
),
|
||||
|i| formula_parenthesized(i, d, v),
|
||||
))(i)
|
||||
@ -535,6 +539,15 @@ mod tests
|
||||
assert_eq!(format_formula("(a <- b <- c) <-> (d <- e <- f)"), "a <- b <- c <-> d <- e <- f");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_compare()
|
||||
{
|
||||
assert_eq!(format_formula("X >= 0"), "X >= 0");
|
||||
assert_eq!(format_formula("N >= 0"), "N >= 0");
|
||||
assert_eq!(format_formula("n < 0"), "n < 0");
|
||||
assert_eq!(format_formula("n >= 0"), "n >= 0");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_exists()
|
||||
{
|
||||
|
@ -489,12 +489,17 @@ mod tests
|
||||
|
||||
assert_eq!(term_as_function("s").declaration.name, "s");
|
||||
assert_eq!(term_as_function("s").declaration.arity, 0);
|
||||
assert!(term_as_function("s").arguments.is_empty());
|
||||
assert_eq!(term_as_function("s()").declaration.name, "s");
|
||||
assert_eq!(term_as_function("s").declaration.arity, 0);
|
||||
assert_eq!(term_as_function("s()").declaration.arity, 0);
|
||||
assert!(term_as_function("s()").arguments.is_empty());
|
||||
assert_eq!(term_as_function("s(1, 2, 3)").declaration.name, "s");
|
||||
assert_eq!(term_as_function("s(1, 2, 3)").declaration.arity, 3);
|
||||
assert_eq!(term_as_function("s(1, 2, 3)").arguments.len(), 3);
|
||||
assert_eq!(term_as_function("s(1, 2, 3)").arguments.remove(0), Term::integer(1));
|
||||
assert_eq!(term_as_function("s(1, 2, 3)").arguments.remove(2), Term::integer(3));
|
||||
|
||||
assert_eq!(format_term("n"), "n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
Loading…
Reference in New Issue
Block a user