Skip to content
Open
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
7 changes: 5 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),

Expand Down Expand Up @@ -1240,8 +1243,8 @@ module.exports = grammar({
spread_parameter: $ => seq(
optional($.modifiers),
$._unannotated_type,
'...',
repeat($._annotation),
'...',
$.variable_declarator,
),

Expand Down
62 changes: 61 additions & 1 deletion test/corpus/expressions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
}

---
Expand All @@ -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)))