mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
comparison
This commit is contained in:
parent
f56965bdb6
commit
6242f7a2e3
|
@ -1,4 +1,4 @@
|
||||||
fun foo a b = a + b;
|
fun foo a b = a == b;
|
||||||
fun bar a b = { a + b };
|
fun bar a b = { a == b };
|
||||||
let res = foo(34, 35);
|
let res = foo(34, 35);
|
||||||
let res = { foo(34, 35) };
|
let res = { foo(34, 35) };
|
|
@ -83,7 +83,9 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
||||||
.or(keyword)
|
.or(keyword)
|
||||||
.recover_with(skip_then_retry_until([]));
|
.recover_with(skip_then_retry_until([]));
|
||||||
|
|
||||||
let comment = just("//").then(take_until(just('\n'))).padded();
|
let comment = just("//").then(take_until(just('\n')))
|
||||||
|
.padded()
|
||||||
|
.ignored();
|
||||||
|
|
||||||
token
|
token
|
||||||
.padded_by(comment.repeated())
|
.padded_by(comment.repeated())
|
||||||
|
@ -192,8 +194,25 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
|
||||||
left: Box::new(lhs),
|
left: Box::new(lhs),
|
||||||
right: Box::new(rhs)
|
right: Box::new(rhs)
|
||||||
}).labelled("term");
|
}).labelled("term");
|
||||||
|
|
||||||
|
let compare = term.clone()
|
||||||
|
.then(
|
||||||
|
choice((
|
||||||
|
just(Token::Operator("==".to_string())).to("=="),
|
||||||
|
just(Token::Operator("!=".to_string())).to("!="),
|
||||||
|
just(Token::Operator("<".to_string())).to("<"),
|
||||||
|
just(Token::Operator(">".to_string())).to(">"),
|
||||||
|
just(Token::Operator("<=".to_string())).to("<="),
|
||||||
|
just(Token::Operator(">=".to_string())).to(">=")))
|
||||||
|
.then(term)
|
||||||
|
.repeated())
|
||||||
|
.foldl(|lhs, (op, rhs)| Expr::Binary {
|
||||||
|
op: op.to_string(),
|
||||||
|
left: Box::new(lhs),
|
||||||
|
right: Box::new(rhs)
|
||||||
|
}).labelled("compare");
|
||||||
|
|
||||||
term
|
compare
|
||||||
}).labelled("expression");
|
}).labelled("expression");
|
||||||
|
|
||||||
let declare = recursive(|decl| {
|
let declare = recursive(|decl| {
|
||||||
|
|
|
@ -24,10 +24,10 @@ fn main() {
|
||||||
if parse_error.is_empty() {
|
if parse_error.is_empty() {
|
||||||
println!("{:#?}", ast);
|
println!("{:#?}", ast);
|
||||||
} else {
|
} else {
|
||||||
eprintln!("{:#?}", parse_error);
|
eprintln!("{:#?}\n(Parser error)", parse_error);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
eprintln!("{:#?}", lex_error);
|
eprintln!("{:#?}\n(Lexer error)", lex_error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue