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),
$.tick,
choice(
seq('(', $.expression, ')'),
$._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(
@ -1387,7 +1393,7 @@ module.exports = grammar({
optional($.aspect_specification),
';',
),
exception_handler: $ => seq(
exception_handler: $ => seq( // RM 11.2
reservedWord('when'),
optional(seq(
$.choice_parameter_specification,
@ -1397,10 +1403,6 @@ module.exports = grammar({
'=>',
$._sequence_of_statements,
),
_exception_handler_list: $ => repeat1(choice(
$.exception_handler,
$.pragma_g,
)),
formal_part: $ => seq( // ARM 6.1
'(',
$._parameter_specification_list,
@ -1687,7 +1689,7 @@ module.exports = grammar({
$._sequence_of_statements,
optional(seq(
reservedWord('exception'),
$._exception_handler_list,
repeat1($.exception_handler),
)),
),
loop_label: $ => seq( // matches label_opt in ada-mode grammar

View File

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

View File

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

62505
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@ -542,3 +542,102 @@ end;
(expression
(term
(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))))))