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 bar a b = { a + b };
|
||||
fun foo a b = a == b;
|
||||
fun bar a b = { a == b };
|
||||
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)
|
||||
.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
|
||||
.padded_by(comment.repeated())
|
||||
|
@ -192,8 +194,25 @@ fn expr_parser() -> impl Parser<Token, Expr, Error = Simple<Token>> + Clone {
|
|||
left: Box::new(lhs),
|
||||
right: Box::new(rhs)
|
||||
}).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");
|
||||
|
||||
let declare = recursive(|decl| {
|
||||
|
|
|
@ -24,10 +24,10 @@ fn main() {
|
|||
if parse_error.is_empty() {
|
||||
println!("{:#?}", ast);
|
||||
} else {
|
||||
eprintln!("{:#?}", parse_error);
|
||||
eprintln!("{:#?}\n(Parser error)", parse_error);
|
||||
}
|
||||
} else {
|
||||
eprintln!("{:#?}", lex_error);
|
||||
eprintln!("{:#?}\n(Lexer error)", lex_error);
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue