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,
|
KwLet, KwMut, KwFun,
|
||||||
KwDo, KwEnd,
|
KwDo, KwEnd,
|
||||||
KwIf, KwThen, KwElse,
|
KwIf, KwThen, KwElse,
|
||||||
KwMatch, KwWith,
|
KwCase, KwOf,
|
||||||
KwReturn,
|
KwReturn,
|
||||||
KwPub,
|
KwPub,
|
||||||
|
|
||||||
|
@ -41,8 +41,8 @@ impl std::fmt::Display for Token {
|
||||||
Token::KwIf => write!(f, "if"),
|
Token::KwIf => write!(f, "if"),
|
||||||
Token::KwThen => write!(f, "then"),
|
Token::KwThen => write!(f, "then"),
|
||||||
Token::KwElse => write!(f, "else"),
|
Token::KwElse => write!(f, "else"),
|
||||||
Token::KwMatch => write!(f, "match"),
|
Token::KwCase => write!(f, "case"),
|
||||||
Token::KwWith => write!(f, "with"),
|
Token::KwOf => write!(f, "of"),
|
||||||
Token::KwReturn => write!(f, "return"),
|
Token::KwReturn => write!(f, "return"),
|
||||||
Token::KwPub => write!(f, "pub"),
|
Token::KwPub => write!(f, "pub"),
|
||||||
|
|
||||||
|
@ -134,8 +134,8 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
|
||||||
"if" => Token::KwIf,
|
"if" => Token::KwIf,
|
||||||
"then" => Token::KwThen,
|
"then" => Token::KwThen,
|
||||||
"else" => Token::KwElse,
|
"else" => Token::KwElse,
|
||||||
"match" => Token::KwMatch,
|
"case" => Token::KwCase,
|
||||||
"with" => Token::KwWith,
|
"of" => Token::KwOf,
|
||||||
"return" => Token::KwReturn,
|
"return" => Token::KwReturn,
|
||||||
"pub" => Token::KwPub,
|
"pub" => Token::KwPub,
|
||||||
_ => Token::Identifier(s),
|
_ => 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())
|
.ignore_then(expr.clone())
|
||||||
.then_ignore(just(Token::KwWith))
|
.then_ignore(just(Token::KwOf))
|
||||||
.then(
|
.then(
|
||||||
just(Token::Pipe)
|
just(Token::Pipe)
|
||||||
.ignore_then(expr.clone())
|
.ignore_then(expr.clone())
|
||||||
|
|
|
@ -1,18 +1,10 @@
|
||||||
fun factorial (n: int) : int = do
|
fun factorial (n: int) : int = do
|
||||||
match n with
|
case n of
|
||||||
| 0 -> return 1
|
| 0 -> return 1
|
||||||
| else return n * factorial(n - 1)
|
| else return n * factorial(n - 1)
|
||||||
end
|
end
|
||||||
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
|
fun main : void = do
|
||||||
let result : int = factorial(5)
|
let result : int = factorial(5)
|
||||||
@write(result)
|
@write(result)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
fun fib (n: int): int = do
|
fun fib (n: int): int = do
|
||||||
if n < 2 then
|
case n of
|
||||||
return n
|
| 1 -> return 1
|
||||||
else
|
| 2 -> return 1
|
||||||
return fib(n - 1) + fib(n - 2)
|
| else -> return fib(n - 1) + fib(n - 2)
|
||||||
end
|
end
|
||||||
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
|
fun print_single (cell: bool): void = do
|
||||||
match cell with
|
case cell of
|
||||||
| true -> @write("█")
|
| true -> @write("█")
|
||||||
| else @write(" ")
|
| else @write(" ")
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ fun cell_merger (a: bool) (b: bool) (c: bool): bool = do
|
||||||
end
|
end
|
||||||
|
|
||||||
fun next (state: vec_bool) (pointer: int): bool = do
|
fun next (state: vec_bool) (pointer: int): bool = do
|
||||||
match pointer with
|
case pointer of
|
||||||
| 0 -> do
|
| 0 -> do
|
||||||
let a: bool = false
|
let a: bool = false
|
||||||
let b: bool = @get(state, 1)
|
let b: bool = @get(state, 1)
|
||||||
|
|
|
@ -16,7 +16,7 @@ end
|
||||||
fun every (a : [any]) (b : [any]): bool = return every_(a, b, 0)
|
fun every (a : [any]) (b : [any]): bool = return every_(a, b, 0)
|
||||||
|
|
||||||
fun eqTuples (a : [any]) (b : [any]) : bool =
|
fun eqTuples (a : [any]) (b : [any]) : bool =
|
||||||
match @len(a) == @len(b) with
|
case @len(a) == @len(b) of
|
||||||
| true -> return every(a, b)
|
| true -> return every(a, b)
|
||||||
| else return false
|
| else return false
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue