diff --git a/grammar.js b/grammar.js index 710ca03..5e7609d 100644 --- a/grammar.js +++ b/grammar.js @@ -200,6 +200,7 @@ module.exports = grammar({ $.table_literal_type, $.union_type, $.parenthesized_type, + $.tuple_type, $.function_type, $.member_type, $.optional_type, @@ -240,6 +241,8 @@ module.exports = grammar({ parenthesized_type: $ => seq('(', $.type, ')'), + tuple_type: $ => seq('(', commaSep2($.type), ')'), + function_type: $ => prec.right(seq( choice('fun', 'function'), '(', @@ -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))); +} diff --git a/test/corpus/annotations.txt b/test/corpus/annotations.txt index 1e81331..ad78400 100644 --- a/test/corpus/annotations.txt +++ b/test/corpus/annotations.txt @@ -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)))))