Skip to content

Commit 17dad33

Browse files
committed
fix: add more allowed reserved identifiers & allow them in annotation type element names
1 parent 333cb0b commit 17dad33

File tree

2 files changed

+58
-7
lines changed

2 files changed

+58
-7
lines changed

grammar.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ module.exports = grammar({
5353
inline: $ => [
5454
$._name,
5555
$._simple_type,
56-
$._reserved_identifier,
5756
$._class_body_declaration,
5857
$._variable_initializer
5958
],
@@ -982,7 +981,7 @@ module.exports = grammar({
982981
annotation_type_element_declaration: $ => seq(
983982
optional($.modifiers),
984983
field('type', $._unannotated_type),
985-
field('name', $.identifier),
984+
field('name', choice($.identifier, $._reserved_identifier)),
986985
'(', ')',
987986
field('dimensions', optional($.dimensions)),
988987
optional($._default_value),
@@ -1191,11 +1190,17 @@ module.exports = grammar({
11911190
field('body', $.block)
11921191
),
11931192

1194-
_reserved_identifier: $ => alias(choice(
1195-
'open',
1196-
'module',
1197-
'record'
1198-
), $.identifier),
1193+
_reserved_identifier: $ => prec(-3, alias(
1194+
choice(
1195+
'open',
1196+
'module',
1197+
'record',
1198+
'with',
1199+
'yield',
1200+
'sealed',
1201+
),
1202+
$.identifier,
1203+
)),
11991204

12001205
this: $ => 'this',
12011206

test/corpus/declarations.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,3 +848,49 @@ non-sealed interface C extends A {}
848848
(type_list
849849
(type_identifier)))
850850
(interface_body)))
851+
852+
====================
853+
Reserved identifiers
854+
====================
855+
856+
public @interface Reserved {
857+
String module();
858+
}
859+
860+
public class Keywords {
861+
public void demo() {
862+
int sealed = 0;
863+
bool yield = false;
864+
}
865+
}
866+
867+
---
868+
869+
(program
870+
(annotation_type_declaration
871+
(modifiers)
872+
(identifier)
873+
(annotation_type_body
874+
(annotation_type_element_declaration
875+
(type_identifier)
876+
(identifier))))
877+
(class_declaration
878+
(modifiers)
879+
(identifier)
880+
(class_body
881+
(method_declaration
882+
(modifiers)
883+
(void_type)
884+
(identifier)
885+
(formal_parameters)
886+
(block
887+
(local_variable_declaration
888+
(integral_type)
889+
(variable_declarator
890+
(identifier)
891+
(decimal_integer_literal)))
892+
(local_variable_declaration
893+
(type_identifier)
894+
(variable_declarator
895+
(identifier)
896+
(false))))))))

0 commit comments

Comments
 (0)