Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ module.exports = grammar({

variant_type: $ => prec.left(seq(
optional('|'),
barSep1($.variant_declaration),
barSep1(choice(
$.variant_declaration,
$.variant_type_spread,
)),
)),

variant_declaration: $ => prec.right(seq(
Expand All @@ -352,6 +355,11 @@ module.exports = grammar({
')',
),

variant_type_spread: $ => seq(
'...',
$.type_identifier,
),

polyvar_type: $ => prec.left(seq(
choice('[', '[>', '[<',),
optional('|'),
Expand Down Expand Up @@ -725,7 +733,13 @@ module.exports = grammar({
call_arguments: $ => seq(
'(',
optional($.uncurry),
optional(commaSep1t($._call_argument)),
choice(
optional(commaSep1t($._call_argument)),
seq(
optional(commaSep1($._call_argument)),
optional(seq(',', $.partial_application)),
),
),
')'
),

Expand Down Expand Up @@ -1439,6 +1453,7 @@ module.exports = grammar({
lparen: $ => alias($._lparen, '('),
rparen: $ => alias($._rparen, ')'),
uncurry: $ => '.',
partial_application: $ => '...',

_reserved_identifier: $ => choice(
'async',
Expand Down
19 changes: 19 additions & 0 deletions test/corpus/functions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,22 @@ async () => body
(source_file
(expression_statement
(function (formal_parameters) (value_identifier))))

===================================================
Partial application
===================================================

let foo = bar(1, 2, ...)

---

(source_file
(let_declaration
(let_binding
(value_identifier)
(call_expression
(value_identifier)
(arguments
(number)
(number)
(partial_application))))))
33 changes: 33 additions & 0 deletions test/corpus/type_declarations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -679,3 +679,36 @@ type t<'a> constraint 'a = t
(type_constraint
(type_identifier)
(type_identifier)))))

================================================================================
Variant type spread
================================================================================

type t = Zero | ...t | Three | Four
type t = | ...t | Three | Four

--------------------------------------------------------------------------------

(source_file
(type_declaration
(type_binding
(type_identifier)
(variant_type
(variant_declaration
(variant_identifier))
(variant_type_spread
(type_identifier))
(variant_declaration
(variant_identifier))
(variant_declaration
(variant_identifier)))))
(type_declaration
(type_binding
(type_identifier)
(variant_type
(variant_type_spread
(type_identifier))
(variant_declaration
(variant_identifier))
(variant_declaration
(variant_identifier))))))