From 6f6cac7c848f979f2edc133ee55dfc84b8d9cfcf Mon Sep 17 00:00:00 2001 From: Emmanuel Briot Date: Mon, 24 Oct 2022 14:45:14 +0200 Subject: [PATCH] Support for allocators --- corpus/statements.txt | 88 +++++++++++++++++++++++++++++++++++++++++++ grammar.js | 29 ++++++++++---- 2 files changed, 110 insertions(+), 7 deletions(-) diff --git a/corpus/statements.txt b/corpus/statements.txt index 38532b0..630ca2d 100644 --- a/corpus/statements.txt +++ b/corpus/statements.txt @@ -624,3 +624,91 @@ end; (statement (simple_statement (null_statement)))))))))))))) + +================================================================================ +Allocators +================================================================================ + +procedure P is +begin + A := new T; + A := new (pkg.pool) T'((F => 1)); +end; + +-------------------------------------------------------------------------------- + +(compilation + (compilation_unit + (proper_body + (subprogram_body + (subprogram_specification + (procedure_specification + (name + (identifier)))) + (handled_sequence_of_statements + (sequence_of_statements + (statement + (simple_statement + (assignment_statement + (name + (identifier)) + (assign_value + (expression + (relation + (simple_expression + (term + (factor + (primary + (allocator + (subtype_indication_paren_constraint + (name + (identifier)))))))))))))) + (statement + (simple_statement + (assignment_statement + (name + (identifier)) + (assign_value + (expression + (relation + (simple_expression + (term + (factor + (primary + (allocator + (subpool_specification + (name + (identifier) + (name + (identifier)))) + (subtype_indication_paren_constraint + (name + (qualified_expression + (name + (identifier)) + (tick) + (aggregate + (record_aggregate + (record_component_association_list + (record_component_association + (expression + (relation + (simple_expression + (term + (factor + (primary + (aggregate + (record_aggregate + (record_component_association_list + (record_component_association + (component_choice_list + (selector_name + (identifier))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (numeric_literal)))))))))))))))))))))))))))))))))))))))))) diff --git a/grammar.js b/grammar.js index 48c2149..81249e9 100644 --- a/grammar.js +++ b/grammar.js @@ -110,6 +110,7 @@ module.exports = grammar({ [$.selector_name, $.primary], [$.formal_derived_type_definition], [$._direct_name, $.aspect_mark], + [$.name, $.attribute_reference, $.qualified_expression], ], @@ -145,10 +146,6 @@ module.exports = grammar({ // name: $ => choice( // $.explicit_dereference, // $.selected_component, -// $.function_call, -// $.character_literal, -// $.qualified_expression, -// '@', // ), // _direct_name: $ => choice( // $.identifier, @@ -166,8 +163,11 @@ module.exports = grammar({ ), $.attribute_reference, $.function_call, - //$.string_literal, // from ada-mode, but seems wrong. - // // Added to primary instead + $.qualified_expression, + '@', + //$.character_literal, // from adamode, seems wrong. + //$.string_literal, // from ada-mode, but seems wrong. + // // Added to primary instead ), name_list: $ => comma_separated_list_of($.name), @@ -517,7 +517,22 @@ module.exports = grammar({ $.name, $.string_literal, // ada-mode puts this in name instead $.character_literal, -// $.allocator, + $.allocator, + ), + allocator: $ => seq( + reservedWord('new'), + optional($.subpool_specification), + $.subtype_indication_paren_constraint, + ), + subtype_indication_paren_constraint: $ => seq( + optional($.null_exclusion), + $.name, + optional($.index_constraint), + ), + subpool_specification: $ => seq( + '(', + $.name, + ')', ), access_type_definition: $ => seq( optional($.null_exclusion),