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,
|
branch::alt,
|
||||||
bytes::complete::tag,
|
bytes::complete::tag,
|
||||||
character::complete::multispace0,
|
character::complete::multispace0,
|
||||||
combinator::{cut, map, map_res},
|
combinator::{cut, map, map_res, peek},
|
||||||
multi::{many1, separated_list1},
|
multi::{many1, separated_list1},
|
||||||
sequence::{delimited, pair, preceded, terminated, tuple},
|
sequence::{delimited, pair, preceded, terminated, tuple},
|
||||||
};
|
};
|
||||||
@ -286,6 +286,8 @@ where
|
|||||||
delimited
|
delimited
|
||||||
(
|
(
|
||||||
multispace0,
|
multispace0,
|
||||||
|
terminated
|
||||||
|
(
|
||||||
alt
|
alt
|
||||||
((
|
((
|
||||||
map
|
map
|
||||||
@ -300,13 +302,13 @@ where
|
|||||||
),
|
),
|
||||||
map
|
map
|
||||||
(
|
(
|
||||||
tag(">"),
|
tag("<"),
|
||||||
|_| crate::ComparisonOperator::Greater,
|
|_| crate::ComparisonOperator::Less,
|
||||||
),
|
),
|
||||||
map
|
map
|
||||||
(
|
(
|
||||||
tag("<"),
|
tag(">"),
|
||||||
|_| crate::ComparisonOperator::Less,
|
|_| crate::ComparisonOperator::Greater,
|
||||||
),
|
),
|
||||||
map
|
map
|
||||||
(
|
(
|
||||||
@ -319,6 +321,8 @@ where
|
|||||||
|_| crate::ComparisonOperator::Equal,
|
|_| crate::ComparisonOperator::Equal,
|
||||||
),
|
),
|
||||||
)),
|
)),
|
||||||
|
peek(nom::combinator::not(tag("-"))),
|
||||||
|
),
|
||||||
multispace0,
|
multispace0,
|
||||||
),
|
),
|
||||||
|i| crate::parse::term(i, d, v),
|
|i| crate::parse::term(i, d, v),
|
||||||
@ -381,13 +385,13 @@ where
|
|||||||
),
|
),
|
||||||
map
|
map
|
||||||
(
|
(
|
||||||
|i| predicate(i, d, v),
|
|i| compare(i, d, v),
|
||||||
crate::Formula::Predicate,
|
crate::Formula::Compare,
|
||||||
),
|
),
|
||||||
map
|
map
|
||||||
(
|
(
|
||||||
|i| compare(i, d, v),
|
|i| predicate(i, d, v),
|
||||||
crate::Formula::Compare,
|
crate::Formula::Predicate,
|
||||||
),
|
),
|
||||||
|i| formula_parenthesized(i, d, v),
|
|i| formula_parenthesized(i, d, v),
|
||||||
))(i)
|
))(i)
|
||||||
@ -535,6 +539,15 @@ mod tests
|
|||||||
assert_eq!(format_formula("(a <- b <- c) <-> (d <- e <- f)"), "a <- b <- c <-> d <- e <- f");
|
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]
|
#[test]
|
||||||
fn parse_exists()
|
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.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()").declaration.name, "s");
|
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.name, "s");
|
||||||
assert_eq!(term_as_function("s(1, 2, 3)").declaration.arity, 3);
|
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(0), Term::integer(1));
|
||||||
assert_eq!(term_as_function("s(1, 2, 3)").arguments.remove(2), Term::integer(3));
|
assert_eq!(term_as_function("s(1, 2, 3)").arguments.remove(2), Term::integer(3));
|
||||||
|
|
||||||
|
assert_eq!(format_term("n"), "n");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
Loading…
Reference in New Issue
Block a user