File tree Expand file tree Collapse file tree 1 file changed +45
-1
lines changed
Expand file tree Collapse file tree 1 file changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -67,11 +67,12 @@ module.exports = grammar({
6767 ) ,
6868
6969 _expr : $ => choice (
70- $ . ident ,
70+ prec ( 1 , $ . ident ) ,
7171 $ . assign_expr ,
7272 $ . call_expr ,
7373 $ . paren_expr ,
7474 $ . as_expr ,
75+ $ . tuple_expr ,
7576 $ . return_expr ,
7677 $ . break_expr ,
7778 $ . cont_expr ,
@@ -135,8 +136,11 @@ module.exports = grammar({
135136 _type : $ => choice (
136137 $ . ident ,
137138 $ . underscore ,
139+ $ . tuple_type ,
138140 ) ,
139141
142+ tuple_type : $ => tuple ( $ . _type , false ) ,
143+
140144 _pattern : $ => choice (
141145 $ . underscore ,
142146 $ . pat_ident ,
@@ -195,6 +199,8 @@ module.exports = grammar({
195199 field ( 'ty' , $ . _type ) ,
196200 ) ) ,
197201
202+ tuple_expr : $ => prec ( 1 , tuple ( $ . _expr , true ) ) ,
203+
198204 return_expr : $ => choice (
199205 $ . _prefix_return ,
200206 $ . _suffix_return ,
@@ -392,3 +398,41 @@ function listSepBy(sep, rule) {
392398 optional ( rule ) ,
393399 ) ;
394400}
401+
402+ /**
403+ * @param {RuleOrLiteral } rule
404+ * @param {boolean } tail_sep
405+ */
406+ function tuple ( rule , tail_sep ) {
407+ if ( tail_sep ) {
408+ return seq (
409+ '(' ,
410+ optional ( seq (
411+ repeat1 ( seq (
412+ rule ,
413+ ',' ,
414+ ) ) ,
415+ optional ( rule ) ,
416+ ) ) ,
417+ ')' ,
418+ ) ;
419+ } else {
420+ return seq (
421+ '(' ,
422+ listSepBy ( ',' , rule ) ,
423+ ')' ,
424+ ) ;
425+ }
426+ // const rep = tail_sep ? repeat1 : repeat;
427+ // return seq(
428+ // '(',
429+ // optional(seq(
430+ // rep(seq(
431+ // rule,
432+ // ',',
433+ // )),
434+ // optional(rule),
435+ // )),
436+ // ')',
437+ // );
438+ }
You can’t perform that action at this time.
0 commit comments