Allow structured binding declarators in pmore places

Refs atom/language-c#325
edge_only_predecessors
Max Brunsfeld 2019-05-08 15:51:47 +07:00
parent 966a467029
commit df7bc44e33
4 changed files with 175587 additions and 176208 deletions

@ -656,27 +656,44 @@ auto [a] = B{};
int main() {
auto &&[b, c] = std::make_tuple(c);
const auto [x, y] {1, 2};
for (const auto &[a, b] : c) {}
}
---
(translation_unit
(structured_binding_declaration (auto) (structured_binding_declarator (identifier)) (compound_literal_expression (type_identifier) (initializer_list)))
(declaration
(auto)
(init_declarator
(structured_binding_declarator (identifier))
(compound_literal_expression (type_identifier) (initializer_list))))
(function_definition
(primitive_type)
(function_declarator (identifier) (parameter_list))
(compound_statement
(structured_binding_declaration
(declaration
(auto)
(reference_declarator (structured_binding_declarator (identifier) (identifier)))
(call_expression
(scoped_identifier (namespace_identifier) (identifier))
(argument_list (identifier))))
(structured_binding_declaration
(init_declarator
(reference_declarator (structured_binding_declarator (identifier) (identifier)))
(call_expression
(scoped_identifier (namespace_identifier) (identifier))
(argument_list (identifier)))))
(declaration
(type_qualifier)
(auto)
(structured_binding_declarator (identifier) (identifier))
(initializer_list (number_literal) (number_literal))))))
(init_declarator
(structured_binding_declarator (identifier) (identifier))
(initializer_list (number_literal) (number_literal))))
(for_range_loop
(for_range_declaration
(type_qualifier)
(auto)
(reference_declarator (structured_binding_declarator
(identifier)
(identifier))))
(identifier)
(compound_statement)))))
==========================
Constexpr declarations

@ -22,8 +22,9 @@ module.exports = grammar(C, {
[$.scoped_type_identifier, $.scoped_field_identifier],
[$.comma_expression, $.initializer_list],
[$._type_specifier, $.optional_type_parameter_declaration],
[$._type_specifier, $._declarator, $._expression],
[$._declarator, $._expression],
[$._expression, $._declarator],
[$._expression, $.structured_binding_declarator],
[$._expression, $._declarator, $._type_specifier],
[$.parameter_list, $.argument_list],
]),
@ -40,7 +41,7 @@ module.exports = grammar(C, {
$.alias_declaration,
$.template_declaration,
$.template_instantiation,
$.structured_binding_declaration,
// $.structured_binding_declaration,
alias($.constructor_or_destructor_definition, $.function_definition)
),
@ -149,19 +150,19 @@ module.exports = grammar(C, {
original
),
structured_binding_declaration: $ => seq(
$._declaration_specifiers,
choice(
alias($.structured_binding_reference_declarator, $.reference_declarator),
$.structured_binding_declarator,
),
choice(
seq('=', choice($.initializer_list, $._expression)),
$.initializer_list,
$.argument_list
),
';'
),
// structured_binding_declaration: $ => seq(
// $._declaration_specifiers,
// choice(
// alias($.structured_binding_reference_declarator, $.reference_declarator),
// $.structured_binding_declarator,
// ),
// choice(
// seq('=', choice($.initializer_list, $._expression)),
// $.initializer_list,
// $.argument_list
// ),
// ';'
// ),
template_declaration: $ => seq(
'template',
@ -361,9 +362,16 @@ module.exports = grammar(C, {
$.scoped_identifier,
$.template_function,
$.operator_name,
$.destructor_name
$.destructor_name,
$.structured_binding_declarator
),
// structured_declarator: $ => seq(
// '[',
// commaSep1($.identifier),
// ']'
// ),
_field_declarator: ($, original) => choice(
original,
alias($.reference_field_declarator, $.reference_declarator),
@ -380,7 +388,7 @@ module.exports = grammar(C, {
reference_field_declarator: $ => prec.dynamic(1, prec.right(seq(choice('&', '&&'), $._field_declarator))),
abstract_reference_declarator: $ => prec.right(seq(choice('&', '&&'), optional($._abstract_declarator))),
structured_binding_reference_declarator: $ => seq(choice('&', '&&'), $.structured_binding_declarator),
// structured_binding_reference_declarator: $ => seq(choice('&', '&&'), $.structured_binding_declarator),
structured_binding_declarator: $ => seq('[', commaSep1($.identifier), ']'),
function_declarator: ($, original) => seq(

108
src/grammar.json vendored

@ -85,10 +85,6 @@
"type": "SYMBOL",
"name": "template_instantiation"
},
{
"type": "SYMBOL",
"name": "structured_binding_declaration"
},
{
"type": "ALIAS",
"content": {
@ -1022,6 +1018,10 @@
{
"type": "SYMBOL",
"name": "destructor_name"
},
{
"type": "SYMBOL",
"name": "structured_binding_declarator"
}
]
},
@ -5316,72 +5316,6 @@
]
}
},
"structured_binding_declaration": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_declaration_specifiers"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "structured_binding_reference_declarator"
},
"named": true,
"value": "reference_declarator"
},
{
"type": "SYMBOL",
"name": "structured_binding_declarator"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "="
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "initializer_list"
},
{
"type": "SYMBOL",
"name": "_expression"
}
]
}
]
},
{
"type": "SYMBOL",
"name": "initializer_list"
},
{
"type": "SYMBOL",
"name": "argument_list"
}
]
},
{
"type": "STRING",
"value": ";"
}
]
},
"template_declaration": {
"type": "SEQ",
"members": [
@ -6088,28 +6022,6 @@
]
}
},
"structured_binding_reference_declarator": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "STRING",
"value": "&"
},
{
"type": "STRING",
"value": "&&"
}
]
},
{
"type": "SYMBOL",
"name": "structured_binding_declarator"
}
]
},
"structured_binding_declarator": {
"type": "SEQ",
"members": [
@ -7239,13 +7151,17 @@
"optional_type_parameter_declaration"
],
[
"_type_specifier",
"_declarator",
"_expression"
"_expression",
"_declarator"
],
[
"_expression",
"structured_binding_declarator"
],
[
"_expression",
"_declarator",
"_expression"
"_type_specifier"
],
[
"parameter_list",

351608
src/parser.c vendored

File diff suppressed because it is too large Load Diff