From 961b0ff130a66f31a9e39025892ecc23a6dca9b1 Mon Sep 17 00:00:00 2001 From: Natapat Samutpong Date: Fri, 1 Apr 2022 15:15:36 +0700 Subject: [PATCH] removed semicolons --- crates/parser/src/lib.rs | 4 -- example/69.hz | 18 ++--- example/case.hz | 12 ---- example/factorial.hz | 25 ++++--- example/match.hz | 12 ++++ example/rule110.hz | 140 +++++++++++++++++++-------------------- example/strings.hz | 18 ++--- 7 files changed, 117 insertions(+), 112 deletions(-) delete mode 100644 example/case.hz create mode 100644 example/match.hz diff --git a/crates/parser/src/lib.rs b/crates/parser/src/lib.rs index 262eb05..469d621 100644 --- a/crates/parser/src/lib.rs +++ b/crates/parser/src/lib.rs @@ -327,14 +327,12 @@ fn expr_parser() -> impl Parser>, Error = Simple .ignore_then(expr.clone()) .then_ignore(just(Token::Arrow)) .then(expr.clone()) - .then_ignore(just(Token::SemiColon)) .repeated() ) .then( just(Token::Pipe) .ignore_then(just(Token::KwElse)) .ignore_then(expr.clone()) - .then_ignore(just(Token::SemiColon)) ) .then_ignore(just(Token::KwEnd)) .map(|((expr, cases), default)| { @@ -361,7 +359,6 @@ fn expr_parser() -> impl Parser>, Error = Simple }).labelled("expression"); expr - .then_ignore(just(Token::SemiColon)) .repeated() .then_ignore(end()) } @@ -389,7 +386,6 @@ mod tests { (Token::Identifier("Int".to_string()), 7..10), (Token::Assign, 11..12), (Token::Int(1), 13..14), - (Token::SemiColon, 14..15), ], 15); assert_eq!(err, vec![]); diff --git a/example/69.hz b/example/69.hz index 0c15b59..303c6c5 100644 --- a/example/69.hz +++ b/example/69.hz @@ -1,14 +1,14 @@ fun add2 (lhs: int) (rhs: int): int = do - return lhs + rhs; -end; + return lhs + rhs +end fun main: void = do - let result: int = add2(34, 35); - @write(result); - @write("\n"); + let result: int = add2(34, 35) + @write(result) + @write("\n") if result == 69 then - @write("big cool"); + @write("big cool") else - @write("not cool"); - end; -end; + @write("not cool") + end +end diff --git a/example/case.hz b/example/case.hz deleted file mode 100644 index 8e30d3c..0000000 --- a/example/case.hz +++ /dev/null @@ -1,12 +0,0 @@ -fun main: void = do - let foo: int = 3; - - match foo with - | 1 -> @write("One"); - | 2 -> @write("Two"); - | 3 -> do - @write("Three"); - end; - | else @write("idk"); - end; -end; diff --git a/example/factorial.hz b/example/factorial.hz index 1de4e13..c0cea7c 100644 --- a/example/factorial.hz +++ b/example/factorial.hz @@ -1,10 +1,19 @@ -fun factorial (n: int): int = do +fun factorial (n: int) : int = do match n with - | 0 -> return 1; - | else return n * factorial(n - 1); - end; -end; + | 0 -> return 1 + | else return n * factorial(n - 1) + end +end -fun main: void = do - factorial(5) |> @write(_); -end; +fun also_factorial (n: int) : int = do + if n == 0 then + return 1 + else + return n * also_factorial(n - 1) + end +end + +fun main : void = do + let result : int = factorial(5) + @write(result) +end \ No newline at end of file diff --git a/example/match.hz b/example/match.hz new file mode 100644 index 0000000..b18a9e3 --- /dev/null +++ b/example/match.hz @@ -0,0 +1,12 @@ +fun main: void = do + let foo: int = 3 + + match foo with + | 1 -> @write("One") + | 2 -> @write("Two") + | 3 -> do + @write("Three") + end + | else @write("idk") + end +end diff --git a/example/rule110.hz b/example/rule110.hz index 8618237..319033a 100644 --- a/example/rule110.hz +++ b/example/rule110.hz @@ -1,93 +1,93 @@ fun print_single (cell: bool): void = do match cell with - | true -> @write("█"); - | else @write(" "); - end; -end; + | true -> @write("█") + | else @write(" ") + end +end fun print_vec (state: vec_bool) (length: int) (curr: int): void = do - if curr == length then @write(""); else + if curr == length then @write("") else do - @get(state, curr) |> print_single(_); - print_vec(state, length, curr + 1); - end; - end; -end; + @get(state, curr) |> print_single(_) + print_vec(state, length, curr + 1) + end + end +end fun cell_merger (a: bool) (b: bool) (c: bool): bool = do if a then if b then if c then - return false; + return false else - return true; - end; + return true + end else if c then - return true; + return true else - return false; - end; - end; + return false + end + end else if b then if c then - return true; + return true else - return true; - end; + return true + end else if c then - return true; + return true else - return false; - end; - end; - end; -end; + return false + end + end + end +end fun next (state: vec_bool) (pointer: int): bool = do - case pointer of + match pointer with | 0 -> do - let a: bool = false; - let b: bool = @get(state, 1); - let c: bool = @get(state, 2); - return cell_merger(a, b, c); - end; + let a: bool = false + let b: bool = @get(state, 1) + let c: bool = @get(state, 2) + return cell_merger(a, b, c) + end | 1 -> do - let a: bool = @get(state, 0); - let b: bool = @get(state, 1); - let c: bool = @get(state, 2); - return cell_merger(a, b, c); - end; + let a: bool = @get(state, 0) + let b: bool = @get(state, 1) + let c: bool = @get(state, 2) + return cell_merger(a, b, c) + end | 2 -> do - let a: bool = @get(state, 1); - let b: bool = @get(state, 2); - let c: bool = @get(state, 3); - return cell_merger(a, b, c); - end; + let a: bool = @get(state, 1) + let b: bool = @get(state, 2) + let c: bool = @get(state, 3) + return cell_merger(a, b, c) + end | 3 -> do - let a: bool = @get(state, 2); - let b: bool = @get(state, 3); - let c: bool = @get(state, 4); - return cell_merger(a, b, c); - end; + let a: bool = @get(state, 2) + let b: bool = @get(state, 3) + let c: bool = @get(state, 4) + return cell_merger(a, b, c) + end | 4 -> do - let a: bool = @get(state, 3); - let b: bool = @get(state, 4); - let c: bool = @get(state, 5); - return cell_merger(a, b, c); - end; + let a: bool = @get(state, 3) + let b: bool = @get(state, 4) + let c: bool = @get(state, 5) + return cell_merger(a, b, c) + end | 5 -> do - return true; - end; - | else return false; - end; -end; + return true + end + | else return false + end +end fun iter (state: vec_bool) (for: int) (curr: int): void = do if curr == for then - @write(""); + @write("") else do let next_state: vec_bool = [ @@ -97,19 +97,19 @@ fun iter (state: vec_bool) (for: int) (curr: int): void = do next(state, 3), next(state, 4), next(state, 5) - ]; + ] - print_vec(next_state, 6, 0); - @write("\n"); - iter(next_state, for, curr + 1); - end; - end; -end; + print_vec(next_state, 6, 0) + @write("\n") + iter(next_state, for, curr + 1) + end + end +end fun main: void = do - let vec: vec_bool = [false, false, false, false, false, true]; - print_vec(vec, 6, 0); - @write("\n"); + let vec: vec_bool = [false, false, false, false, false, true] + print_vec(vec, 6, 0) + @write("\n") - iter(vec, 20, 0); -end; + iter(vec, 20, 0) +end diff --git a/example/strings.hz b/example/strings.hz index d04faaf..be6eea4 100644 --- a/example/strings.hz +++ b/example/strings.hz @@ -1,16 +1,16 @@ fun main: void = do - let str: string = "Hello, World"; + let str: string = "Hello, World" -- Matching string(s) match str with - | "Hello, World" -> @write("yes\n"); - | else @write("no\n"); - end; + | "Hello, World" -> @write("yes\n") + | else @write("no\n") + end -- Indexing character in string - let foo: string = @get(str, 0); + let foo: string = @get(str, 0) match foo with - | "H" -> @write("still yes"); - | else @write("no H"); - end; -end; + | "H" -> @write("still yes") + | else @write("no H") + end +end