diff --git a/grammar.js b/grammar.js index a97fd9f..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), @@ -1240,8 +1243,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..74df819 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) { } --- @@ -1951,3 +1951,63 @@ 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)))) + +================================================================================ +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)))