From ef003b25b850eb8c8fb9a00c07b2bc4a1ba764a8 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Thu, 5 Jun 2025 13:40:36 -0700 Subject: [PATCH 1/3] fix: annotations parsing order for spread parameters --- grammar.js | 2 +- test/corpus/expressions.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/grammar.js b/grammar.js index a97fd9f..01b34f6 100644 --- a/grammar.js +++ b/grammar.js @@ -1240,8 +1240,8 @@ module.exports = grammar({ spread_parameter: $ => seq( optional($.modifiers), $._unannotated_type, - '...', repeat($._annotation), + '...', $.variable_declarator, ), diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index 6eeb260..40e06e3 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -1934,7 +1934,7 @@ for (int i = 0, _ = sideEffect(); i < 10; i++) { } Annotations before a spread parameter's ellipsis ================================================================================ -void foo(int... @Foo x) { +void foo(int @Foo ... x) { } --- From b0657401030ccd103f1b6ebac238871dd0bbb023 Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Wed, 11 Jun 2025 11:48:20 -0700 Subject: [PATCH 2/3] fix: allow type use annotations in catch params --- grammar.js | 5 ++++- test/corpus/expressions.txt | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/grammar.js b/grammar.js index 01b34f6..d1fb26d 100644 --- a/grammar.js +++ b/grammar.js @@ -634,7 +634,10 @@ module.exports = grammar({ $._variable_declarator_id, ), - catch_type: $ => sep1($._unannotated_type, '|'), + catch_type: $ => seq( + $._unannotated_type, // first type's annotations will be parsed as modifiers + repeat(seq('|', $._type)), + ), finally_clause: $ => seq('finally', $.block), diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index 40e06e3..b8b8a10 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -1951,3 +1951,38 @@ void foo(int @Foo ... x) { (variable_declarator (identifier)))) (block))) + +================================================================================ +Annotations in a catch type +================================================================================ + +try { +} catch (@A1 @A2 final @A3 @A4 T1 | @A5 @A6 T2 e) { +} + +--- + +(program + (try_statement + (block) + (catch_clause + (catch_formal_parameter + (modifiers + (marker_annotation + (identifier)) + (marker_annotation + (identifier)) + (marker_annotation + (identifier)) + (marker_annotation + (identifier))) + (catch_type + (type_identifier) + (annotated_type + (marker_annotation + (identifier)) + (marker_annotation + (identifier)) + (type_identifier))) + (identifier)) + (block)))) From 6018d681d319aada6d9fe1b8a8d17f9f4d6c758e Mon Sep 17 00:00:00 2001 From: Abhinav Singh Date: Thu, 5 Jun 2025 13:41:41 -0700 Subject: [PATCH 3/3] test: annotations before an array's bracket --- test/corpus/expressions.txt | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/corpus/expressions.txt b/test/corpus/expressions.txt index b8b8a10..74df819 100644 --- a/test/corpus/expressions.txt +++ b/test/corpus/expressions.txt @@ -1986,3 +1986,28 @@ try { (type_identifier))) (identifier)) (block)))) + +================================================================================ +Annotations before an array's bracket +================================================================================ + +void foo(int @Foo @Bar [] x) { +} + +--- + +(program + (method_declaration + (void_type) + (identifier) + (formal_parameters + (formal_parameter + (array_type + (integral_type) + (dimensions + (marker_annotation + (identifier)) + (marker_annotation + (identifier)))) + (identifier))) + (block)))