Skip to content

Commit

Permalink
feat: tuple types
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed Jan 24, 2024
1 parent 6ebdac8 commit 56ad7c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
16 changes: 16 additions & 0 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ module.exports = grammar({
$.table_literal_type,
$.union_type,
$.parenthesized_type,
$.tuple_type,
$.function_type,
$.member_type,
$.optional_type,
Expand Down Expand Up @@ -240,6 +241,8 @@ module.exports = grammar({

parenthesized_type: $ => seq('(', $.type, ')'),

tuple_type: $ => seq('(', commaSep2($.type), ')'),

function_type: $ => prec.right(seq(
choice('fun', 'function'),
'(',
Expand Down Expand Up @@ -325,3 +328,16 @@ function commaSep(rule) {
function commaSep1(rule) {
return seq(rule, repeat(seq(',', rule)));
}

// commaSep2

/**
* Creates a rule to match two or more of the rules separated by a comma
*
* @param {Rule} rule
*
* @return {SeqRule}
*/
function commaSep2(rule) {
return seq(rule, seq(',', rule), repeat(seq(',', rule)));
}
29 changes: 29 additions & 0 deletions test/corpus/annotations.txt
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,32 @@ Test an Indexed Field
(indexed_field
(string))
(builtin_type)))

=========================
Test a Tuple Type
=========================

@field public iter fun(self: Stack): ((fun(i: integer, item: any): integer, any), Stack, integer)

---

(documentation
(field_annotation
(qualifier)
(identifier)
(function_type
(parameter
(identifier))
(tuple_type
(parenthesized_type
(function_type
(parameter
(identifier)
(identifier))
(parameter
(identifier)
(builtin_type))
(identifier)
(builtin_type)))
(identifier)
(identifier)))))

0 comments on commit 56ad7c4

Please sign in to comment.