mirror of
https://github.com/azur1s/bobbylisp.git
synced 2024-10-16 02:37:40 -05:00
change case expression keywords
This commit is contained in:
parent
7e707d6103
commit
cd722dc1c1
|
@ -68,7 +68,7 @@ Hazure is also [expression-oriented](https://en.wikipedia.org/wiki/Expression-or
|
|||
```
|
||||
9) Case matching
|
||||
```sml
|
||||
case 1 + 1 of
|
||||
match 1 + 1 with
|
||||
| 2 -> @write("Yes");
|
||||
| else @write("How?");
|
||||
end;
|
||||
|
|
|
@ -211,12 +211,12 @@ pub fn expr_to_ir(expr: &Expr) -> (Option<IRKind>, Option<LoweringError>) {
|
|||
}
|
||||
|
||||
// If there is no `Hole` in the args then return early
|
||||
if indexes.is_empty() {
|
||||
return_err!(LoweringError {
|
||||
span: rhs.1.clone(),
|
||||
message: "Expected hole in piping".to_string(),
|
||||
});
|
||||
}
|
||||
// if indexes.is_empty() {
|
||||
// return_err!(LoweringError {
|
||||
// span: rhs.1.clone(),
|
||||
// message: "Expected hole in piping".to_string(),
|
||||
// });
|
||||
// }
|
||||
|
||||
// Remove the `Hole` from the args
|
||||
let mut new_args = args.0.clone();
|
||||
|
|
|
@ -6,7 +6,7 @@ pub enum Token {
|
|||
KwLet, KwMut, KwFun,
|
||||
KwDo, KwEnd,
|
||||
KwIf, KwThen, KwElse,
|
||||
KwCase, KwOf,
|
||||
KwMatch, KwWith,
|
||||
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::KwCase => write!(f, "case"),
|
||||
Token::KwOf => write!(f, "of"),
|
||||
Token::KwMatch => write!(f, "match"),
|
||||
Token::KwWith => write!(f, "with"),
|
||||
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,
|
||||
"case" => Token::KwCase,
|
||||
"of" => Token::KwOf,
|
||||
"match" => Token::KwMatch,
|
||||
"with" => Token::KwWith,
|
||||
"return" => Token::KwReturn,
|
||||
"pub" => Token::KwPub,
|
||||
_ => Token::Identifier(s),
|
||||
|
|
|
@ -319,9 +319,9 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
|
|||
)
|
||||
});
|
||||
|
||||
let case = just(Token::KwCase)
|
||||
let match_ = just(Token::KwMatch)
|
||||
.ignore_then(expr.clone())
|
||||
.then_ignore(just(Token::KwOf))
|
||||
.then_ignore(just(Token::KwWith))
|
||||
.then(
|
||||
just(Token::Pipe)
|
||||
.ignore_then(expr.clone())
|
||||
|
@ -356,7 +356,7 @@ fn expr_parser() -> impl Parser<Token, Vec<Spanned<Expr>>, Error = Simple<Token>
|
|||
.or(return_)
|
||||
.or(do_block)
|
||||
.or(if_block)
|
||||
.or(case)
|
||||
.or(match_)
|
||||
.or(pipeline)
|
||||
}).labelled("expression");
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fun main: void = do
|
||||
let foo: int = 3;
|
||||
|
||||
case foo of
|
||||
match foo with
|
||||
| 1 -> @write("One");
|
||||
| 2 -> @write("Two");
|
||||
| 3 -> do
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
fun main: void = do
|
||||
let foo: int = 69;
|
||||
|
||||
case foo of
|
||||
match foo with
|
||||
| 1 -> @write("One");
|
||||
| 2 -> @write("Two");
|
||||
| 3 -> do
|
|
@ -1,5 +1,5 @@
|
|||
fun factorial (n: int): int = do
|
||||
case n of
|
||||
match n with
|
||||
| 0 -> return 1;
|
||||
| else return n * factorial(n - 1);
|
||||
end;
|
||||
|
|
|
@ -7,7 +7,7 @@ end;
|
|||
fun main: void = do
|
||||
let input: string = @read("Enter your name:");
|
||||
|
||||
case input of
|
||||
match input with
|
||||
| "" -> @write("I don't know your name :(");
|
||||
\ say_hi(input);
|
||||
end;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
fun print_single (cell: bool): void = do
|
||||
case cell of
|
||||
match cell with
|
||||
| true -> @write("█");
|
||||
| else @write(" ");
|
||||
end;
|
||||
|
|
Loading…
Reference in a new issue