From 20decd8677debaed05f28cbf950eb25d3be6422e Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Sat, 12 Feb 2022 18:51:43 +0700 Subject: [PATCH] optional semicolons!! --- example/hello_world.hyc | 9 +++++++-- src/front/parser.rs | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/example/hello_world.hyc b/example/hello_world.hyc index b397959..062bc84 100644 --- a/example/hello_world.hyc +++ b/example/hello_world.hyc @@ -1,5 +1,10 @@ func join :: (a, b) = { let result :: String = from(a, b); - return result; + return result }; -let foo :: String = join("f", "oo"); \ No newline at end of file + +func main :: () = { + let foo :: String = join("f", "oo"); + print(foo); + return 0 +}; \ No newline at end of file diff --git a/src/front/parser.rs b/src/front/parser.rs index 8aedf5c..8b7bf4a 100644 --- a/src/front/parser.rs +++ b/src/front/parser.rs @@ -1,7 +1,7 @@ use nom::{ branch::alt, bytes::complete::take, - combinator::{verify, map}, + combinator::{verify, map, opt}, Err, error::{Error, ErrorKind}, IResult, @@ -155,7 +155,7 @@ fn parse_return_stmt(input: Tokens) -> IResult { delimited( tag_return, parse_expr_lowest, - tag_semicolon, + opt(tag_semicolon), ), Stmt::Return, )(input) @@ -168,7 +168,7 @@ fn parse_call_stmt(input: Tokens) -> IResult { tag_lparen, parse_exprs, tag_rparen, - tag_semicolon, + opt(tag_semicolon), )), |(ident, _, args, _, _)| Stmt::Call(ident, args), )(input) @@ -189,7 +189,7 @@ fn parse_func_stmt(input: Tokens) -> IResult { tag_rparen, tag_assign, parse_block_stmt, - tag_semicolon, + opt(tag_semicolon), )), |(_, ident, _, _, params, _, _, block, _)| Stmt::Func(ident, params, block), )(input) @@ -204,7 +204,7 @@ fn parse_let_stmt(input: Tokens) -> IResult { parse_ident, tag_assign, parse_expr_lowest, - tag_semicolon, + opt(tag_semicolon), )), |(_, ident, _, typehint, _, expr, _)| Stmt::Let(ident, typehint, expr), )(input)