File tree Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Expand file tree Collapse file tree 2 files changed +20
-5
lines changed Original file line number Diff line number Diff line change 1
1
fn number_as_word do match it {
2
2
2 then "two"
3
3
1 then "one"
4
+ 3, 4 then "three or four"
4
5
_ then "too big"
5
6
}
6
7
7
8
debug(number_as_word(1)) # expect: "one"
8
9
debug(number_as_word(2)) # expect: "two"
9
- debug(number_as_word(3)) # expect: "too big"
10
+ debug(number_as_word(3)) # expect: "three or four"
11
+ debug(number_as_word(4)) # expect: "three or four"
12
+ debug(number_as_word(5)) # expect: "too big"
10
13
11
14
fn word_to_number do match it {
15
+ "zero",
16
+ "none", then 0
12
17
"one" then 1
13
18
"two" then 2
14
- _ then 0
19
+ _ then -1
15
20
}
16
21
debug(word_to_number("one")) # expect: 1
17
22
debug(word_to_number("two")) # expect: 2
18
- debug(word_to_number("other")) # expect: 0
23
+ debug(word_to_number("zero")) # expect: 0
24
+ debug(word_to_number("none")) # expect: 0
25
+ debug(word_to_number("other")) # expect: -1
19
26
20
27
fn is_empty do match it {
21
28
[] then true
Original file line number Diff line number Diff line change @@ -326,10 +326,18 @@ module Lit
326
326
branches = [] of Tuple (Expr , Expr )
327
327
328
328
until check(TokenType ::RIGHT_BRACE ) || at_end?
329
- pattern = expression
329
+ patterns = [expression] of Expr
330
+ while match?(TokenType ::COMMA )
331
+ ignore_newlines
332
+ # Allow trailing comma by checking if we're at the end of the match block
333
+ break if check(TokenType ::THEN )
334
+ patterns << expression
335
+ end
336
+
330
337
consume(TokenType ::THEN , " I was expecting 'then' after the match pattern." )
331
338
332
- branches << {pattern, expression}
339
+ body = expression
340
+ branches += patterns.map { |p | {p, body}.as(Tuple (Expr , Expr )) }
333
341
consume_line(" I was expecting a newline after the match case." )
334
342
335
343
ignore_newlines
You can’t perform that action at this time.
0 commit comments