Correct parsing of discriminant constraints in allocators.
The existing grammar was causing discriminant constraints in allocators to be incorrectly parsed as function calls. This change modifies the grammar to more accurately follow the grammar of the language and corrects the issue. Updated the test corpus to add additional allocator tests with numerous subtype indications and qualified expressions for more extensive testing.
This commit is contained in:
parent
ba0894efa0
commit
6c3dc1f0ae
19
grammar.js
19
grammar.js
|
|
@ -97,6 +97,7 @@ module.exports = grammar({
|
||||||
[$._name, $.package_body_stub],
|
[$._name, $.package_body_stub],
|
||||||
[$._name, $._subtype_indication],
|
[$._name, $._subtype_indication],
|
||||||
[$._name, $._subtype_indication, $.component_choice_list],
|
[$._name, $._subtype_indication, $.component_choice_list],
|
||||||
|
[$._name, $._subtype_mark],
|
||||||
[$.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],
|
||||||
|
|
@ -158,6 +159,10 @@ module.exports = grammar({
|
||||||
$.identifier,
|
$.identifier,
|
||||||
$.string_literal,
|
$.string_literal,
|
||||||
),
|
),
|
||||||
|
_subtype_mark: $ => choice(
|
||||||
|
$.identifier,
|
||||||
|
$.selected_component,
|
||||||
|
$._attribute_reference),
|
||||||
|
|
||||||
selected_component: $ => prec.left(seq( // RM 4.1.3
|
selected_component: $ => prec.left(seq( // RM 4.1.3
|
||||||
field('prefix', $._name),
|
field('prefix', $._name),
|
||||||
|
|
@ -565,12 +570,22 @@ module.exports = grammar({
|
||||||
allocator: $ => seq(
|
allocator: $ => seq(
|
||||||
reservedWord('new'),
|
reservedWord('new'),
|
||||||
optional($.subpool_specification),
|
optional($.subpool_specification),
|
||||||
|
choice(
|
||||||
$._subtype_indication_paren_constraint,
|
$._subtype_indication_paren_constraint,
|
||||||
|
$.qualified_expression)
|
||||||
),
|
),
|
||||||
_subtype_indication_paren_constraint: $ => seq(
|
_subtype_indication_paren_constraint: $ => seq(
|
||||||
|
// Ada 2012+ doesn't allow null exclusion here -- RM 4.8(2)
|
||||||
|
// Before Ada 2012, null exclusion raises Constraint_Error (AI05-0104)
|
||||||
optional($.null_exclusion),
|
optional($.null_exclusion),
|
||||||
$._name,
|
field('subtype_mark', $._subtype_mark),
|
||||||
optional($.index_constraint),
|
optional(choice(
|
||||||
|
// Choose discriminant_constraint over index_constraint,
|
||||||
|
// when syntax ambiguity arises, to avoid potential
|
||||||
|
// highlighting of names in a discriminant_constraint as
|
||||||
|
// subtype names.
|
||||||
|
prec.dynamic(1, $.discriminant_constraint),
|
||||||
|
$.index_constraint)),
|
||||||
),
|
),
|
||||||
subpool_specification: $ => seq(
|
subpool_specification: $ => seq(
|
||||||
'(',
|
'(',
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,23 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"_subtype_mark": {
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "identifier"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "selected_component"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "_attribute_reference"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
"selected_component": {
|
"selected_component": {
|
||||||
"type": "PREC_LEFT",
|
"type": "PREC_LEFT",
|
||||||
"value": 0,
|
"value": 0,
|
||||||
|
|
@ -2771,9 +2788,18 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_subtype_indication_paren_constraint"
|
"name": "_subtype_indication_paren_constraint"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "qualified_expression"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|
@ -2793,15 +2819,32 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
"type": "FIELD",
|
||||||
|
"name": "subtype_mark",
|
||||||
|
"content": {
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "_name"
|
"name": "_subtype_mark"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "CHOICE",
|
"type": "CHOICE",
|
||||||
"members": [
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "CHOICE",
|
||||||
|
"members": [
|
||||||
|
{
|
||||||
|
"type": "PREC_DYNAMIC",
|
||||||
|
"value": 1,
|
||||||
|
"content": {
|
||||||
|
"type": "SYMBOL",
|
||||||
|
"name": "discriminant_constraint"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "SYMBOL",
|
"type": "SYMBOL",
|
||||||
"name": "index_constraint"
|
"name": "index_constraint"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "BLANK"
|
"type": "BLANK"
|
||||||
|
|
@ -15362,6 +15405,10 @@
|
||||||
"_subtype_indication",
|
"_subtype_indication",
|
||||||
"component_choice_list"
|
"component_choice_list"
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
"_name",
|
||||||
|
"_subtype_mark"
|
||||||
|
],
|
||||||
[
|
[
|
||||||
"attribute_definition_clause",
|
"attribute_definition_clause",
|
||||||
"_attribute_reference"
|
"_attribute_reference"
|
||||||
|
|
|
||||||
|
|
@ -458,10 +458,10 @@
|
||||||
{
|
{
|
||||||
"type": "allocator",
|
"type": "allocator",
|
||||||
"named": true,
|
"named": true,
|
||||||
"fields": {},
|
"fields": {
|
||||||
"children": {
|
"subtype_mark": {
|
||||||
"multiple": true,
|
"multiple": true,
|
||||||
"required": true,
|
"required": false,
|
||||||
"types": [
|
"types": [
|
||||||
{
|
{
|
||||||
"type": "attribute_designator",
|
"type": "attribute_designator",
|
||||||
|
|
@ -483,14 +483,6 @@
|
||||||
"type": "identifier",
|
"type": "identifier",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "index_constraint",
|
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "null_exclusion",
|
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "qualified_expression",
|
"type": "qualified_expression",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -511,10 +503,6 @@
|
||||||
"type": "string_literal",
|
"type": "string_literal",
|
||||||
"named": true
|
"named": true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"type": "subpool_specification",
|
|
||||||
"named": true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"type": "target_name",
|
"type": "target_name",
|
||||||
"named": true
|
"named": true
|
||||||
|
|
@ -530,6 +518,33 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"children": {
|
||||||
|
"multiple": true,
|
||||||
|
"required": false,
|
||||||
|
"types": [
|
||||||
|
{
|
||||||
|
"type": "discriminant_constraint",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "index_constraint",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "null_exclusion",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "qualified_expression",
|
||||||
|
"named": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "subpool_specification",
|
||||||
|
"named": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"type": "array_component_association",
|
"type": "array_component_association",
|
||||||
"named": true,
|
"named": true,
|
||||||
|
|
|
||||||
71660
src/parser.c
71660
src/parser.c
File diff suppressed because it is too large
Load Diff
|
|
@ -441,7 +441,24 @@ Allocators
|
||||||
|
|
||||||
procedure P is
|
procedure P is
|
||||||
begin
|
begin
|
||||||
|
-- subtype indication
|
||||||
A := new T;
|
A := new T;
|
||||||
|
A := new not null T;
|
||||||
|
A := new T'Base;
|
||||||
|
A := new T (1 .. 10, 1 .. 20);
|
||||||
|
A := new T (100);
|
||||||
|
A := new T (F => 100);
|
||||||
|
A := new T (F);
|
||||||
|
|
||||||
|
-- qualified expression
|
||||||
|
A := new T'(0, 255, 0);
|
||||||
|
A := new T'(F => 1);
|
||||||
|
A := new T'(1 .. 10 => (1 .. 20 => 0.0));
|
||||||
|
A := new T'(55);
|
||||||
|
A := new T'(F);
|
||||||
|
A := new T'Base'(5);
|
||||||
|
|
||||||
|
-- subpool specification
|
||||||
A := new (pkg.pool) T'((F => 1));
|
A := new (pkg.pool) T'((F => 1));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
@ -451,25 +468,194 @@ end;
|
||||||
(compilation_unit
|
(compilation_unit
|
||||||
(subprogram_body
|
(subprogram_body
|
||||||
(procedure_specification
|
(procedure_specification
|
||||||
(identifier))
|
name: (identifier))
|
||||||
|
(comment)
|
||||||
(handled_sequence_of_statements
|
(handled_sequence_of_statements
|
||||||
(assignment_statement
|
(assignment_statement
|
||||||
(identifier)
|
variable_name: (identifier)
|
||||||
(expression
|
(expression
|
||||||
(term
|
(term
|
||||||
(allocator
|
(allocator
|
||||||
(identifier)))))
|
subtype_mark: (identifier)))))
|
||||||
(assignment_statement
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
(null_exclusion)
|
||||||
|
subtype_mark: (identifier)))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
subtype_mark: (tick)
|
||||||
|
subtype_mark: (attribute_designator
|
||||||
|
(identifier))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(index_constraint
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
(numeric_literal))
|
||||||
|
(term
|
||||||
|
(numeric_literal)))
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
(numeric_literal))
|
||||||
|
(term
|
||||||
|
(numeric_literal))))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(discriminant_constraint
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal))))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(discriminant_constraint
|
||||||
|
(discriminant_association
|
||||||
(identifier)
|
(identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal)))))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
subtype_mark: (identifier)
|
||||||
|
(discriminant_constraint
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
name: (identifier))))))))
|
||||||
|
(comment)
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
(qualified_expression
|
||||||
|
subtype_name: (identifier)
|
||||||
|
(tick)
|
||||||
|
(positional_array_aggregate
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal)))
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal)))
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal)))))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
(qualified_expression
|
||||||
|
subtype_name: (identifier)
|
||||||
|
(tick)
|
||||||
|
(record_aggregate
|
||||||
|
(record_component_association_list
|
||||||
|
(component_choice_list
|
||||||
|
(identifier))
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal))))))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
(qualified_expression
|
||||||
|
subtype_name: (identifier)
|
||||||
|
(tick)
|
||||||
|
(named_array_aggregate
|
||||||
|
(array_component_association
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
(numeric_literal))
|
||||||
|
(term
|
||||||
|
(numeric_literal)))))
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(named_array_aggregate
|
||||||
|
(array_component_association
|
||||||
|
(discrete_choice_list
|
||||||
|
(discrete_choice
|
||||||
|
(range_g
|
||||||
|
(term
|
||||||
|
(numeric_literal))
|
||||||
|
(term
|
||||||
|
(numeric_literal)))))
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal))))))))))))))
|
||||||
|
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
(qualified_expression
|
||||||
|
subtype_name: (identifier)
|
||||||
|
(tick)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal))))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
(qualified_expression
|
||||||
|
subtype_name: (identifier)
|
||||||
|
(tick)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
name: (identifier))))))))
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(allocator
|
||||||
|
(qualified_expression
|
||||||
|
subtype_name: (identifier)
|
||||||
|
subtype_name: (tick)
|
||||||
|
subtype_name: (attribute_designator
|
||||||
|
(identifier))
|
||||||
|
(tick)
|
||||||
|
(expression
|
||||||
|
(term
|
||||||
|
(numeric_literal))))))))
|
||||||
|
(comment)
|
||||||
|
(assignment_statement
|
||||||
|
variable_name: (identifier)
|
||||||
(expression
|
(expression
|
||||||
(term
|
(term
|
||||||
(allocator
|
(allocator
|
||||||
(subpool_specification
|
(subpool_specification
|
||||||
(selected_component
|
subpool_handle_name: (selected_component
|
||||||
(identifier)
|
prefix: (identifier)
|
||||||
(identifier)))
|
selector_name: (identifier)))
|
||||||
(qualified_expression
|
(qualified_expression
|
||||||
(identifier)
|
subtype_name: (identifier)
|
||||||
(tick)
|
(tick)
|
||||||
(expression
|
(expression
|
||||||
(term
|
(term
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user