val defn with ids

Problem
-------
`val` definitions with multiple identifiers are not supported.

Solution
--------
This implements `identifiers`, which acts like a pattern.
text_sliders
Eugene Yokota 2023-05-27 21:21:40 +07:00
parent 4072a37b9c
commit ec70a4503a
2 changed files with 17 additions and 2 deletions

@ -852,6 +852,7 @@ Value definitions
class A {
val b = 1
val c : String = "d"
val a1, a2 = pair
}
--------------------------------------------------------------------------------
@ -866,7 +867,12 @@ class A {
(val_definition
(identifier)
(type_identifier)
(string)))))
(string))
(val_definition
(identifiers
(identifier)
(identifier))
(identifier)))))
================================================================================
Variable declarations

@ -417,7 +417,10 @@ module.exports = grammar({
val_definition: $ => prec(PREC.binding_def, seq(
$._start_val,
field('pattern', $._pattern),
field('pattern', choice(
$._pattern,
$.identifiers
)),
optional(seq(':', field('type', $._type))),
'=',
field('value', $._indentable_expression)
@ -1293,6 +1296,12 @@ module.exports = grammar({
_identifier: $ => choice($.identifier, $.operator_identifier),
identifiers: $ => prec.left(-1, seq(
$.identifier,
',',
commaSep1($.identifier)
)),
wildcard: $ => '_',
/**