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],
|
[$.attribute_definition_clause, $._attribute_reference],
|
||||||
[$.component_choice_list, $.discrete_choice],
|
[$.component_choice_list, $.discrete_choice],
|
||||||
[$.component_choice_list, $.positional_array_aggregate],
|
[$.component_choice_list, $.positional_array_aggregate],
|
||||||
|
[$.discriminant_association, $._parenthesized_expression],
|
||||||
],
|
],
|
||||||
inline: $ => [
|
inline: $ => [
|
||||||
$._name_not_function_call,
|
$._name_not_function_call,
|
||||||
|
|
@ -413,11 +414,17 @@ module.exports = grammar({
|
||||||
field('subtype_mark', $._name_not_function_call),
|
field('subtype_mark', $._name_not_function_call),
|
||||||
optional($._constraint),
|
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),
|
comma_separated_list_of($.discriminant_association),
|
||||||
')',
|
')',
|
||||||
),
|
),
|
||||||
|
),
|
||||||
discriminant_association: $ => seq( // RM 3.7.1
|
discriminant_association: $ => seq( // RM 3.7.1
|
||||||
optional(seq(
|
optional(seq(
|
||||||
list_of('|', $._name_for_component_choice),
|
list_of('|', $._name_for_component_choice),
|
||||||
|
|
|
||||||
|
|
@ -1868,6 +1868,13 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"discriminant_constraint": {
|
"discriminant_constraint": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_parenthesized_expression"
|
||||||
|
},
|
||||||
|
{
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
"members": [
|
"members": [
|
||||||
{
|
{
|
||||||
|
|
@ -1904,6 +1911,8 @@
|
||||||
"value": ")"
|
"value": ")"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"discriminant_association": {
|
"discriminant_association": {
|
||||||
"type": "SEQ",
|
"type": "SEQ",
|
||||||
|
|
@ -15331,6 +15340,10 @@
|
||||||
[
|
[
|
||||||
"component_choice_list",
|
"component_choice_list",
|
||||||
"positional_array_aggregate"
|
"positional_array_aggregate"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"discriminant_association",
|
||||||
|
"_parenthesized_expression"
|
||||||
]
|
]
|
||||||
],
|
],
|
||||||
"precedences": [],
|
"precedences": [],
|
||||||
|
|
|
||||||
|
|
@ -2588,9 +2588,29 @@
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": true,
|
||||||
"types": [
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "case_expression",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "declare_expression",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "discriminant_association",
|
"type": "discriminant_association",
|
||||||
"named": true
|
"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
|
(handled_sequence_of_statements
|
||||||
(null_statement)))))
|
(null_statement)))))
|
||||||
|
|
||||||
========================
|
================================================================================
|
||||||
Record with discr
|
Record with discr
|
||||||
========================
|
================================================================================
|
||||||
|
|
||||||
procedure Proc is
|
procedure Proc is
|
||||||
type Rec (Len : Natural) is null record;
|
type Rec (Len : Natural) is null record;
|
||||||
R : Rec (0);
|
R : Rec (0);
|
||||||
|
R2 : Rec (if N > 0 then 1 else 0);
|
||||||
begin
|
begin
|
||||||
null;
|
null;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
--------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
(compilation
|
(compilation
|
||||||
(compilation_unit
|
(compilation_unit
|
||||||
|
|
@ -540,7 +541,23 @@ end;
|
||||||
(identifier)
|
(identifier)
|
||||||
(identifier)
|
(identifier)
|
||||||
(discriminant_constraint
|
(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
|
(expression
|
||||||
(term
|
(term
|
||||||
(numeric_literal)))))))
|
(numeric_literal)))))))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user