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

change case syntax

This commit is contained in:
Natapat Samutpong 2022-03-21 05:54:55 +07:00
parent 09ea710580
commit 990ee95372
7 changed files with 11 additions and 12 deletions

View file

@ -70,7 +70,7 @@ Hazure is also [expression-oriented](https://en.wikipedia.org/wiki/Expression-or
```sml
case 1 + 1 of
| 2 -> @write("Yes");
\ @write("How?");
| else @write("How?");
end;
```
10) Do notation. It allows you to have multiple expression because something like right hand side of the function declaration `fun a: int = ...` can only have 1 expression. Do allows you to bypass that.

View file

@ -70,8 +70,8 @@ impl std::fmt::Display for IRKind {
)
},
IRKind::Fun { ref public, ref name, ref return_type_hint, ref args, ref body } => {
write!(f, "(fun{} {} {} {} {})",
if *public { "export" } else { "" },
write!(f, "(fun{} {} :{} [{}] {})",
if *public { " export" } else { "" },
name,
return_type_hint,
args.iter().map(|(name, type_hint)| format!(":{} {}", name, type_hint)).collect::<Vec<_>>().join(" "),

View file

@ -16,7 +16,7 @@ pub enum Token {
// Operators
Plus, Minus, Multiply, Divide, Modulus,
Pipe, EndPipe,
Pipe,
Not, Equal, NotEqual, Less, Greater,
Pipeline, Arrow,
@ -62,7 +62,6 @@ impl std::fmt::Display for Token {
Token::Greater => write!(f, ">"),
Token::Pipeline => write!(f, "|>"),
Token::Pipe => write!(f, "|"),
Token::EndPipe => write!(f, "\\"),
Token::Arrow => write!(f, "->"),
Token::Assign => write!(f, "="),
@ -102,7 +101,6 @@ pub fn lexer() -> impl Parser<char, Vec<(Token, Span)>, Error = Simple<char>> {
just("|>").to(Token::Pipeline),
just("|").to(Token::Pipe),
just("\\").to(Token::EndPipe),
just('<').to(Token::Less),
just('>').to(Token::Greater),

View file

@ -317,7 +317,8 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
.repeated()
)
.then(
just(Token::EndPipe)
just(Token::Pipe)
.ignore_then(just(Token::KwElse))
.ignore_then(expr.clone())
.then_ignore(just(Token::SemiColon))
)

View file

@ -7,6 +7,6 @@ fun main: void = do
| 3 -> do
@write("Three");
end;
\ @write("idk");
| else @write("idk");
end;
end;

View file

@ -1,7 +1,7 @@
fun factorial (n: int): int = do
case n of
| 0 -> return 1;
\ return n * factorial(n - 1);
| else return n * factorial(n - 1);
end;
end;