mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
change match keyword
This commit is contained in:
parent
1a517da5a1
commit
fac86781dd
|
@ -6,7 +6,7 @@ pub enum Token {
|
|||
KwLet, KwMut, KwFun,
|
||||
KwDo, KwEnd,
|
||||
KwIf, KwThen, KwElse,
|
||||
KwMatch, KwWith,
|
||||
KwCase, KwOf,
|
||||
KwReturn,
|
||||
KwPub,
|
||||
|
||||
|
@ -41,8 +41,8 @@ impl std::fmt::Display for Token {
|
|||
Token::KwIf => write!(f, "if"),
|
||||
Token::KwThen => write!(f, "then"),
|
||||
Token::KwElse => write!(f, "else"),
|
||||
Token::KwMatch => write!(f, "match"),
|
||||
Token::KwWith => write!(f, "with"),
|
||||
Token::KwCase => write!(f, "case"),
|
||||
Token::KwOf => write!(f, "of"),
|
||||
Token::KwReturn => write!(f, "return"),
|
||||
Token::KwPub => write!(f, "pub"),
|
||||
|
||||
|
@ -134,8 +134,8 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
|||
"if" => Token::KwIf,
|
||||
"then" => Token::KwThen,
|
||||
"else" => Token::KwElse,
|
||||
"match" => Token::KwMatch,
|
||||
"with" => Token::KwWith,
|
||||
"case" => Token::KwCase,
|
||||
"of" => Token::KwOf,
|
||||
"return" => Token::KwReturn,
|
||||
"pub" => Token::KwPub,
|
||||
_ => Token::Identifier(s),
|
||||
|
|
|
@ -335,9 +335,9 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
|
|||
)
|
||||
});
|
||||
|
||||
let match_ = just(Token::KwMatch)
|
||||
let match_ = just(Token::KwCase)
|
||||
.ignore_then(expr.clone())
|
||||
.then_ignore(just(Token::KwWith))
|
||||
.then_ignore(just(Token::KwOf))
|
||||
.then(
|
||||
just(Token::Pipe)
|
||||
.ignore_then(expr.clone())
|
||||
|
|
|
@ -1,18 +1,10 @@
|
|||
fun factorial (n: int) : int = do
|
||||
match n with
|
||||
case n of
|
||||
| 0 -> return 1
|
||||
| else return n * factorial(n - 1)
|
||||
end
|
||||
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)
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
fun fib (n: int): int = do
|
||||
if n < 2 then
|
||||
return n
|
||||
else
|
||||
return fib(n - 1) + fib(n - 2)
|
||||
case n of
|
||||
| 1 -> return 1
|
||||
| 2 -> return 1
|
||||
| else -> return fib(n - 1) + fib(n - 2)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
3
example/hello.hz
Normal file
3
example/hello.hz
Normal file
|
@ -0,0 +1,3 @@
|
|||
fun main: void = do
|
||||
@write("Hello, World!")
|
||||
end
|
|
@ -1,3 +0,0 @@
|
|||
fun main: void = do
|
||||
@emit("console.log('Hello, World!')");
|
||||
end;
|
|
@ -1,3 +0,0 @@
|
|||
fun main: void = do
|
||||
@write("Hello, World!");
|
||||
end;
|
|
@ -1,14 +0,0 @@
|
|||
fun say_hi (name: string): void = do
|
||||
@write("Hi ");
|
||||
@write(name);
|
||||
@write("!");
|
||||
end;
|
||||
|
||||
fun main: void = do
|
||||
let input: string = @read("Enter your name:");
|
||||
|
||||
match input with
|
||||
| "" -> @write("I don't know your name :(");
|
||||
\ say_hi(input);
|
||||
end;
|
||||
end;
|
|
@ -1,5 +0,0 @@
|
|||
-- Run this file from root path
|
||||
fun main: void = do
|
||||
@read_file("./example/io/read_file.hz")
|
||||
|> @write(_);
|
||||
end;
|
|
@ -1,3 +0,0 @@
|
|||
fun main: void = do
|
||||
@write_file("console.log('Hello, World!')", "hello.js");
|
||||
end;
|
|
@ -1,5 +1,5 @@
|
|||
fun print_single (cell: bool): void = do
|
||||
match cell with
|
||||
case cell of
|
||||
| true -> @write("█")
|
||||
| else @write(" ")
|
||||
end
|
||||
|
@ -47,7 +47,7 @@ fun cell_merger (a: bool) (b: bool) (c: bool): bool = do
|
|||
end
|
||||
|
||||
fun next (state: vec_bool) (pointer: int): bool = do
|
||||
match pointer with
|
||||
case pointer of
|
||||
| 0 -> do
|
||||
let a: bool = false
|
||||
let b: bool = @get(state, 1)
|
||||
|
|
|
@ -16,7 +16,7 @@ end
|
|||
fun every (a : [any]) (b : [any]): bool = return every_(a, b, 0)
|
||||
|
||||
fun eqTuples (a : [any]) (b : [any]) : bool =
|
||||
match @len(a) == @len(b) with
|
||||
case @len(a) == @len(b) of
|
||||
| true -> return every(a, b)
|
||||
| else return false
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue