Merge pull request #139 from ahumenberger/fix-local-variable-declaration

fix, Local variable declaration with generic types and scoped type id…
pull/502/head
Yoann Padioleau 2023-02-23 20:14:04 +07:00 committed by GitHub
commit 3c24aa9365
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 113 additions and 68 deletions

@ -91,7 +91,6 @@ module.exports = grammar({
$.false,
$.character_literal,
$.string_literal,
$.text_block,
$.null_literal
),
@ -361,7 +360,7 @@ module.exports = grammar({
optional($.class_body)
)),
field_access: $ => prec.dynamic(PREC.OBJ_ACCESS, seq(
field_access: $ => seq(
field('object', choice($.primary_expression, $.super)),
optional(seq(
'.',
@ -369,7 +368,7 @@ module.exports = grammar({
)),
'.',
field('field', choice($.identifier, $._reserved_identifier, $.this))
)),
),
array_access: $ => seq(
field('array', $.primary_expression),

102
src/grammar.json vendored

@ -2749,76 +2749,72 @@
}
},
"field_access": {
"type": "PREC_DYNAMIC",
"value": 16,
"content": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "object",
"content": {
"type": "CHOICE",
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "object",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "primary_expression"
},
{
"type": "SYMBOL",
"name": "super"
}
]
}
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "primary_expression"
"type": "STRING",
"value": "."
},
{
"type": "SYMBOL",
"name": "super"
}
]
},
{
"type": "BLANK"
}
},
{
]
},
{
"type": "STRING",
"value": "."
},
{
"type": "FIELD",
"name": "field",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "."
},
{
"type": "SYMBOL",
"name": "super"
}
]
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "BLANK"
"type": "SYMBOL",
"name": "_reserved_identifier"
},
{
"type": "SYMBOL",
"name": "this"
}
]
},
{
"type": "STRING",
"value": "."
},
{
"type": "FIELD",
"name": "field",
"content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "_reserved_identifier"
},
{
"type": "SYMBOL",
"name": "this"
}
]
}
}
]
}
}
]
},
"array_access": {
"type": "SEQ",

24
src/parser.c vendored

@ -5228,7 +5228,7 @@ static inline bool sym_identifier_character_set_1(int32_t c) {
: c <= 67826)
: (c <= 67829 || (c < 67872
? (c >= 67840 && c <= 67861)
: c <= 67880)))))))))))))));
: c <= 67883)))))))))))))));
}
static inline bool sym_identifier_character_set_2(int32_t c) {
@ -5742,7 +5742,7 @@ static inline bool sym_identifier_character_set_2(int32_t c) {
: c <= 67826)
: (c <= 67829 || (c < 67872
? (c >= 67840 && c <= 67861)
: c <= 67880)))))))))))))));
: c <= 67883)))))))))))))));
}
static inline bool sym_identifier_character_set_3(int32_t c) {
@ -6256,7 +6256,7 @@ static inline bool sym_identifier_character_set_3(int32_t c) {
: c <= 67826)
: (c <= 67829 || (c < 67872
? (c >= 67840 && c <= 67861)
: c <= 67880)))))))))))))));
: c <= 67883)))))))))))))));
}
static inline bool sym_identifier_character_set_4(int32_t c) {
@ -6770,7 +6770,7 @@ static inline bool sym_identifier_character_set_4(int32_t c) {
: (c <= 67742 || (c >= 67808 && c <= 67826)))
: (c <= 67829 || (c < 67872
? (c >= 67840 && c <= 67861)
: c <= 67880)))))))))))))));
: c <= 67883)))))))))))))));
}
static bool ts_lex(TSLexer *lexer, TSStateId state) {
@ -66657,10 +66657,10 @@ static const TSParseActionEntry ts_parse_actions[] = {
[1255] = {.entry = {.count = 2, .reusable = false}}, REDUCE(aux_sym_annotation_type_body_repeat1, 2), SHIFT_REPEAT(687),
[1258] = {.entry = {.count = 1, .reusable = true}}, SHIFT(261),
[1260] = {.entry = {.count = 1, .reusable = true}}, SHIFT(219),
[1262] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 3, .dynamic_precedence = 16, .production_id = 31),
[1264] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 3, .dynamic_precedence = 16, .production_id = 31),
[1266] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 3, .dynamic_precedence = 16, .production_id = 32),
[1268] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 3, .dynamic_precedence = 16, .production_id = 32),
[1262] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 3, .production_id = 31),
[1264] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 3, .production_id = 31),
[1266] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 3, .production_id = 32),
[1268] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 3, .production_id = 32),
[1270] = {.entry = {.count = 1, .reusable = false}}, SHIFT(1081),
[1272] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_primary_expression, 1, .production_id = 1),
[1274] = {.entry = {.count = 1, .reusable = false}}, SHIFT(167),
@ -66668,10 +66668,10 @@ static const TSParseActionEntry ts_parse_actions[] = {
[1278] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_primary_expression, 1, .production_id = 1),
[1280] = {.entry = {.count = 1, .reusable = true}}, SHIFT(107),
[1282] = {.entry = {.count = 1, .reusable = false}}, SHIFT(1083),
[1284] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 5, .dynamic_precedence = 16, .production_id = 105),
[1286] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 5, .dynamic_precedence = 16, .production_id = 105),
[1288] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 5, .dynamic_precedence = 16, .production_id = 106),
[1290] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 5, .dynamic_precedence = 16, .production_id = 106),
[1284] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 5, .production_id = 105),
[1286] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 5, .production_id = 105),
[1288] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_field_access, 5, .production_id = 106),
[1290] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_field_access, 5, .production_id = 106),
[1292] = {.entry = {.count = 1, .reusable = false}}, REDUCE(sym_array_access, 4, .production_id = 72),
[1294] = {.entry = {.count = 1, .reusable = true}}, REDUCE(sym_array_access, 4, .production_id = 72),
[1296] = {.entry = {.count = 1, .reusable = false}}, SHIFT(218),

@ -1164,3 +1164,53 @@ $cibleVisée2 = 2;
(assignment_expression
(identifier)
(decimal_integer_literal))))
================================================================================
Local variable declaration with scoped type identifiers
================================================================================
util.List<Integer> x = null;
java.util.List<Integer> x = null;
java.util.List<java.lang.Integer> x = null;
--------------------------------------------------------------------------------
(program
(local_variable_declaration
(generic_type
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_arguments
(type_identifier)))
(variable_declarator
(identifier)
(null_literal)))
(local_variable_declaration
(generic_type
(scoped_type_identifier
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_identifier))
(type_arguments
(type_identifier)))
(variable_declarator
(identifier)
(null_literal)))
(local_variable_declaration
(generic_type
(scoped_type_identifier
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_identifier))
(type_arguments
(scoped_type_identifier
(scoped_type_identifier
(type_identifier)
(type_identifier))
(type_identifier))))
(variable_declarator
(identifier)
(null_literal))))