mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 07:14:46 +00:00
Parse && and ||
This commit is contained in:
parent
79951cec5e
commit
21c98d6364
2 changed files with 21 additions and 0 deletions
|
@ -404,10 +404,12 @@ where I: Stream<Item = char, Position = IndentablePosition>,
|
||||||
I::Error: ParseError<I::Item, I::Range, I::Position>
|
I::Error: ParseError<I::Item, I::Range, I::Position>
|
||||||
{
|
{
|
||||||
choice((
|
choice((
|
||||||
|
string("&&").map(|_| Operator::And),
|
||||||
attempt(string("==")).map(|_| Operator::Equals),
|
attempt(string("==")).map(|_| Operator::Equals),
|
||||||
attempt(string("<=")).map(|_| Operator::LessThanOrEq),
|
attempt(string("<=")).map(|_| Operator::LessThanOrEq),
|
||||||
attempt(string(">=")).map(|_| Operator::GreaterThanOrEq),
|
attempt(string(">=")).map(|_| Operator::GreaterThanOrEq),
|
||||||
attempt(string("|>")).map(|_| Operator::Pizza),
|
attempt(string("|>")).map(|_| Operator::Pizza),
|
||||||
|
string("||").map(|_| Operator::Or),
|
||||||
char('+').map(|_| Operator::Plus),
|
char('+').map(|_| Operator::Plus),
|
||||||
char('-').map(|_| Operator::Minus),
|
char('-').map(|_| Operator::Minus),
|
||||||
char('*').map(|_| Operator::Star),
|
char('*').map(|_| Operator::Star),
|
||||||
|
|
|
@ -1392,4 +1392,23 @@ mod test_parse {
|
||||||
""))
|
""))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn compare_and() {
|
||||||
|
assert_eq!(
|
||||||
|
parse_with_precedence("x > 1 || True"),
|
||||||
|
Ok((Operator(
|
||||||
|
loc_box(
|
||||||
|
Operator(
|
||||||
|
loc_box(Var("x".to_string())),
|
||||||
|
loc(GreaterThan),
|
||||||
|
loc_box(Int(1))
|
||||||
|
)
|
||||||
|
),
|
||||||
|
loc(Or),
|
||||||
|
loc_box(ApplyVariant("True".to_string(), None))
|
||||||
|
),
|
||||||
|
""))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue