Skip to content

Commit 016ee9f

Browse files
committed
fix: allow or patterns to begin with a |
1 parent 927a1b5 commit 016ee9f

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

grammar.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ module.exports = grammar({
12081208
),
12091209

12101210
match_pattern: $ => seq(
1211-
choice($._pattern, alias($.closure_expression, $.closure_pattern)),
1211+
$._pattern,
12121212
optional(seq('if', field('condition', $._condition))),
12131213
),
12141214

@@ -1422,10 +1422,9 @@ module.exports = grammar({
14221422
$._pattern,
14231423
),
14241424

1425-
or_pattern: $ => prec.left(-2, seq(
1426-
$._pattern,
1427-
'|',
1428-
$._pattern,
1425+
or_pattern: $ => prec.left(-2, choice(
1426+
seq($._pattern, '|', $._pattern),
1427+
seq('|', $._pattern),
14291428
)),
14301429

14311430
// Section - Literals

test/corpus/patterns.txt

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ match x {
165165
d.. => a,
166166
}
167167

168+
match name {
169+
| "IPV6_FLOWINFO"
170+
| "IPV6_FLOWLABEL_MGR"
171+
| "IPV6_FLOWINFO_SEND" => true,
172+
_ => false,
173+
}
174+
168175
--------------------------------------------------------------------------------
169176

170177
(source_file
@@ -221,7 +228,26 @@ match x {
221228
pattern: (match_pattern
222229
(range_pattern
223230
(identifier)))
224-
value: (identifier))))))
231+
value: (identifier)))))
232+
(expression_statement
233+
(match_expression
234+
value: (identifier)
235+
body: (match_block
236+
(match_arm
237+
pattern: (match_pattern
238+
(or_pattern
239+
(or_pattern
240+
(or_pattern
241+
(string_literal
242+
(string_content)))
243+
(string_literal
244+
(string_content)))
245+
(string_literal
246+
(string_content))))
247+
value: (boolean_literal))
248+
(match_arm
249+
pattern: (match_pattern)
250+
value: (boolean_literal))))))
225251

226252
================================================================================
227253
Or patterns
@@ -251,12 +277,6 @@ fn foo((1 | 2 | 3): u8) {}
251277

252278
if let x!() | y!() = () {}
253279

254-
// Discomment after box pattern land on master
255-
// let box (A | B | C);
256-
257-
// Not handled cause devs didn't got into agreement if should be acceptd or not
258-
// |Ok(x) | Err(x)| expr();
259-
260280
--------------------------------------------------------------------------------
261281

262282
(source_file
@@ -387,11 +407,7 @@ if let x!() | y!() = () {}
387407
macro: (identifier)
388408
(token_tree)))
389409
value: (unit_expression))
390-
consequence: (block)))
391-
(line_comment)
392-
(line_comment)
393-
(line_comment)
394-
(line_comment))
410+
consequence: (block))))
395411

396412
================================================================================
397413
Inline const or Const blocks as pattern

0 commit comments

Comments
 (0)