1
1
Fork 0
mirror of https://github.com/azur1s/bobbylisp.git synced 2024-10-16 02:37:40 -05:00

Compare commits

..

No commits in common. "6b984f87110cec808c97ee21d78f601bd24cedca" and "9c1e0927da6f86a89832c9b4260eb8a7d4ab6a80" have entirely different histories.

7 changed files with 115 additions and 119 deletions

View file

@ -277,6 +277,7 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
});
let do_block = expr.clone()
.then_ignore(just(Token::SemiColon))
.repeated()
.delimited_by(
just(Token::KwDo),
@ -298,13 +299,13 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
.then(
do_block.clone()
.or(expr.clone())
)
).then_ignore(just(Token::SemiColon))
.then_ignore(just(Token::KwElse))
.then(
do_block.clone()
.or(expr.clone())
)
).then_ignore(just(Token::SemiColon))
.then_ignore(just(Token::KwEnd))
.map(|((cond, then), else_)| {
@ -326,12 +327,14 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
.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)| {
@ -358,6 +361,7 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
}).labelled("expression");
expr
.then_ignore(just(Token::SemiColon))
.repeated()
.then_ignore(end())
}
@ -385,6 +389,7 @@ 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![]);

View file

@ -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;

12
example/case.hz Normal file
View file

@ -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;

View file

@ -1,19 +1,10 @@
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 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
fun main: void = do
factorial(5) |> @write(_);
end;

View file

@ -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

View file

@ -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
match pointer with
case pointer of
| 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;

View file

@ -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;