diff --git a/example/ex.hyc b/example/ex.hyc index b1d878f..360de97 100644 --- a/example/ex.hyc +++ b/example/ex.hyc @@ -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) }; \ No newline at end of file diff --git a/src/front/parse.rs b/src/front/parse.rs index fae79b2..3fe04fa 100644 --- a/src/front/parse.rs +++ b/src/front/parse.rs @@ -83,7 +83,9 @@ pub fn lexer() -> impl Parser, Error = Simple> { .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> + 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| { diff --git a/src/main.rs b/src/main.rs index d96d138..3c02e9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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); } }, }