Fix pattern definition (#38) (#39)

pull/101/head
Stevan Milic 2021-10-10 19:34:22 +07:00 committed by GitHub
parent 98f703493d
commit 0a3dd53a7f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 68181 additions and 67369 deletions

@ -30,6 +30,7 @@ val x = y match {
case 1 : Int => 2
case a : B with C => d
case _: B | _: C => 3
case Object.Constant => 3
}
---
@ -47,6 +48,9 @@ val x = y match {
(alternative_pattern
(typed_pattern (wildcard) (type_identifier))
(typed_pattern (wildcard) (type_identifier)))
(integer_literal))
(case_clause
(stable_identifier (identifier) (identifier))
(integer_literal))))))
============================
@ -136,6 +140,7 @@ Capture patterns
val x = y match {
case a @ B(1) => a
case b @ C(d @ (e @ X, _: Y)) => e
case req @ (POST | GET) -> Root / "test" => 5
}
---
@ -156,4 +161,11 @@ val x = y match {
(tuple_pattern
(capture_pattern (identifier) (identifier))
(typed_pattern (wildcard) (type_identifier))))))
(identifier))))))
(identifier))
(case_clause
(infix_pattern
(infix_pattern
(capture_pattern (identifier)
(tuple_pattern (alternative_pattern (identifier) (identifier))))
(operator_identifier) (identifier)) (operator_identifier) (string))
(integer_literal))))))

@ -474,6 +474,7 @@ module.exports = grammar({
_pattern: $ => choice(
$.identifier,
$.stable_identifier,
$.capture_pattern,
$.tuple_pattern,
$.case_class_pattern,
@ -497,20 +498,20 @@ module.exports = grammar({
field('right', $._pattern),
)),
capture_pattern: $ => prec(PREC.assign, seq(
capture_pattern: $ => prec(PREC.field, seq(
field('name', $.identifier),
'@',
field('pattern', $._pattern)
)),
typed_pattern: $ => prec(-1, seq(
typed_pattern: $ => prec.right(seq(
field('pattern', $._pattern),
':',
field('type', $._type)
)),
// TODO: Flatten this.
alternative_pattern: $ => prec.left(-2, seq(
alternative_pattern: $ => prec.left(-1, seq(
$._pattern,
'|',
$._pattern

12
src/grammar.json vendored

@ -2495,6 +2495,10 @@
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "stable_identifier"
},
{
"type": "SYMBOL",
"name": "capture_pattern"
@ -2640,7 +2644,7 @@
},
"capture_pattern": {
"type": "PREC",
"value": 2,
"value": 6,
"content": {
"type": "SEQ",
"members": [
@ -2668,8 +2672,8 @@
}
},
"typed_pattern": {
"type": "PREC",
"value": -1,
"type": "PREC_RIGHT",
"value": 0,
"content": {
"type": "SEQ",
"members": [
@ -2698,7 +2702,7 @@
},
"alternative_pattern": {
"type": "PREC_LEFT",
"value": -2,
"value": -1,
"content": {
"type": "SEQ",
"members": [

@ -101,6 +101,10 @@
"type": "null_literal",
"named": true
},
{
"type": "stable_identifier",
"named": true
},
{
"type": "string",
"named": true

135513
src/parser.c vendored

File diff suppressed because it is too large Load Diff