fix support of pragmas inside exception handlers

This was copied from ada_mode, but results in
 confusion when we have statements after the pragma

Fix allocates with if-expression, which no longer
 needs double-parenthesis.
This commit is contained in:
Emmanuel Briot 2022-12-14 12:59:09 +01:00
parent dbd3401b14
commit 39697ddca8
5 changed files with 31222 additions and 31446 deletions

View File

@ -283,8 +283,14 @@ module.exports = grammar({
field('subtype_name', $._name), field('subtype_name', $._name),
$.tick, $.tick,
choice( choice(
seq('(', $.expression, ')'),
$._aggregate, $._aggregate,
// In the RM grammar, this is a simple '(expression)', but
// conditional expression would require a second nested pair of
// parenthesis, whereas this is not mandatory anymore in the
// text of the RM.
// seq('(', $.expression, ')'),
$._parenthesized_expression,
), ),
), ),
compilation_unit: $ => choice( compilation_unit: $ => choice(
@ -1387,7 +1393,7 @@ module.exports = grammar({
optional($.aspect_specification), optional($.aspect_specification),
';', ';',
), ),
exception_handler: $ => seq( exception_handler: $ => seq( // RM 11.2
reservedWord('when'), reservedWord('when'),
optional(seq( optional(seq(
$.choice_parameter_specification, $.choice_parameter_specification,
@ -1397,10 +1403,6 @@ module.exports = grammar({
'=>', '=>',
$._sequence_of_statements, $._sequence_of_statements,
), ),
_exception_handler_list: $ => repeat1(choice(
$.exception_handler,
$.pragma_g,
)),
formal_part: $ => seq( // ARM 6.1 formal_part: $ => seq( // ARM 6.1
'(', '(',
$._parameter_specification_list, $._parameter_specification_list,
@ -1687,7 +1689,7 @@ module.exports = grammar({
$._sequence_of_statements, $._sequence_of_statements,
optional(seq( optional(seq(
reservedWord('exception'), reservedWord('exception'),
$._exception_handler_list, repeat1($.exception_handler),
)), )),
), ),
loop_label: $ => seq( // matches label_opt in ada-mode grammar loop_label: $ => seq( // matches label_opt in ada-mode grammar

View File

@ -927,26 +927,13 @@
{ {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "expression"
},
{
"type": "STRING",
"value": ")"
}
]
},
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_aggregate" "name": "_aggregate"
},
{
"type": "SYMBOL",
"name": "_parenthesized_expression"
} }
] ]
} }
@ -8322,17 +8309,8 @@
"_exception_handler_list": { "_exception_handler_list": {
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL", "type": "SYMBOL",
"name": "exception_handler" "name": "exception_handler"
},
{
"type": "SYMBOL",
"name": "pragma_g"
}
]
} }
}, },
"formal_part": { "formal_part": {

View File

@ -8885,6 +8885,14 @@
"type": "array_delta_aggregate", "type": "array_delta_aggregate",
"named": true "named": true
}, },
{
"type": "case_expression",
"named": true
},
{
"type": "declare_expression",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -8893,6 +8901,10 @@
"type": "extension_aggregate", "type": "extension_aggregate",
"named": true "named": true
}, },
{
"type": "if_expression",
"named": true
},
{ {
"type": "named_array_aggregate", "type": "named_array_aggregate",
"named": true "named": true
@ -8905,6 +8917,10 @@
"type": "positional_array_aggregate", "type": "positional_array_aggregate",
"named": true "named": true
}, },
{
"type": "quantified_expression",
"named": true
},
{ {
"type": "record_aggregate", "type": "record_aggregate",
"named": true "named": true

62505
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@ -542,3 +542,102 @@ end;
(expression (expression
(term (term
(target_name))))))))))))) (target_name)))))))))))))
=======
if-expressions
=======
procedure P is
begin
S := new String'((if N /= "" then N else "12"));
S := new String'(if N /= "" then N else "12");
end;
-----
(compilation
(compilation_unit
(subprogram_body
(procedure_specification
(identifier))
(handled_sequence_of_statements
(assignment_statement
(identifier)
(expression
(term
(allocator
(qualified_expression
(identifier)
(tick)
(expression
(term
(if_expression
(expression
(term
(identifier))
(relational_operator)
(term
(string_literal)))
(expression
(term
(identifier)))
(expression
(term
(string_literal)))))))))))
(assignment_statement
(identifier)
(expression
(term
(allocator
(qualified_expression
(identifier)
(tick)
(if_expression
(expression
(term
(identifier))
(relational_operator)
(term
(string_literal)))
(expression
(term
(identifier)))
(expression
(term
(string_literal)))))))))))))
=======
Re-raise
=======
procedure P is
begin
null;
exception
when others =>
Proc;
pragma Assert (True);
raise;
end;
------
(compilation
(compilation_unit
(subprogram_body
(procedure_specification
(identifier))
(handled_sequence_of_statements
(null_statement)
(exception_handler
(exception_choice_list
(exception_choice))
(procedure_call_statement
(identifier))
(pragma_g
(identifier)
(pragma_argument_association
(expression
(term
(identifier)))))
(raise_statement))))))