Allow if-expression for discriminant constraints
The rule (not visible in the RM grammar) is that if we have a single positional discriminant, we can omit the extra pair of parenthesis.
This commit is contained in:
parent
7fe1b1edb4
commit
faa006e5fd
|
|
@ -107,6 +107,7 @@ module.exports = grammar({
|
|||
[$.attribute_definition_clause, $._attribute_reference],
|
||||
[$.component_choice_list, $.discrete_choice],
|
||||
[$.component_choice_list, $.positional_array_aggregate],
|
||||
[$.discriminant_association, $._parenthesized_expression],
|
||||
],
|
||||
inline: $ => [
|
||||
$._name_not_function_call,
|
||||
|
|
@ -413,11 +414,17 @@ module.exports = grammar({
|
|||
field('subtype_mark', $._name_not_function_call),
|
||||
optional($._constraint),
|
||||
),
|
||||
discriminant_constraint: $ => seq( // RM 3.7.1
|
||||
discriminant_constraint: $ => choice( // RM 3.7.1
|
||||
// If we have a single positional discriminant, it can be an
|
||||
// if-expression without additional parenthesis "A : R (if cond then
|
||||
// 1 else 0)" but otherwise extra parenthesis are needed.
|
||||
$._parenthesized_expression, // not in ARM
|
||||
seq(
|
||||
'(',
|
||||
comma_separated_list_of($.discriminant_association),
|
||||
')',
|
||||
),
|
||||
),
|
||||
discriminant_association: $ => seq( // RM 3.7.1
|
||||
optional(seq(
|
||||
list_of('|', $._name_for_component_choice),
|
||||
|
|
|
|||
|
|
@ -1868,6 +1868,13 @@
|
|||
]
|
||||
},
|
||||
"discriminant_constraint": {
|
||||
"type": "CHOICE",
|
||||
"members": [
|
||||
{
|
||||
"type": "SYMBOL",
|
||||
"name": "_parenthesized_expression"
|
||||
},
|
||||
{
|
||||
"type": "SEQ",
|
||||
"members": [
|
||||
{
|
||||
|
|
@ -1904,6 +1911,8 @@
|
|||
"value": ")"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"discriminant_association": {
|
||||
"type": "SEQ",
|
||||
|
|
@ -15331,6 +15340,10 @@
|
|||
[
|
||||
"component_choice_list",
|
||||
"positional_array_aggregate"
|
||||
],
|
||||
[
|
||||
"discriminant_association",
|
||||
"_parenthesized_expression"
|
||||
]
|
||||
],
|
||||
"precedences": [],
|
||||
|
|
|
|||
|
|
@ -2588,9 +2588,29 @@
|
|||
"multiple": true,
|
||||
"required": true,
|
||||
"types": [
|
||||
{
|
||||
"type": "case_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "declare_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "discriminant_association",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "if_expression",
|
||||
"named": true
|
||||
},
|
||||
{
|
||||
"type": "quantified_expression",
|
||||
"named": true
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
|
|||
64430
src/parser.c
64430
src/parser.c
File diff suppressed because it is too large
Load Diff
|
|
@ -508,18 +508,19 @@ end;
|
|||
(handled_sequence_of_statements
|
||||
(null_statement)))))
|
||||
|
||||
========================
|
||||
================================================================================
|
||||
Record with discr
|
||||
========================
|
||||
================================================================================
|
||||
|
||||
procedure Proc is
|
||||
type Rec (Len : Natural) is null record;
|
||||
R : Rec (0);
|
||||
R2 : Rec (if N > 0 then 1 else 0);
|
||||
begin
|
||||
null;
|
||||
end;
|
||||
|
||||
--------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
|
|
@ -540,7 +541,23 @@ end;
|
|||
(identifier)
|
||||
(identifier)
|
||||
(discriminant_constraint
|
||||
(discriminant_association
|
||||
(expression
|
||||
(term
|
||||
(numeric_literal)))))
|
||||
(object_declaration
|
||||
(identifier)
|
||||
(identifier)
|
||||
(discriminant_constraint
|
||||
(if_expression
|
||||
(expression
|
||||
(term
|
||||
(identifier))
|
||||
(relational_operator)
|
||||
(term
|
||||
(numeric_literal)))
|
||||
(expression
|
||||
(term
|
||||
(numeric_literal)))
|
||||
(expression
|
||||
(term
|
||||
(numeric_literal)))))))
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user