From 160d197c599652ee38cabf8c315c0145527af266 Mon Sep 17 00:00:00 2001 From: Emmanuel Briot Date: Fri, 21 Oct 2022 15:44:53 +0200 Subject: [PATCH] Support for arrays and object declarations --- corpus/arrays.txt | 314 ++++++++++++++++++++++++++++++++++++++++++++++ grammar.js | 53 ++++++-- 2 files changed, 359 insertions(+), 8 deletions(-) create mode 100644 corpus/arrays.txt diff --git a/corpus/arrays.txt b/corpus/arrays.txt new file mode 100644 index 0000000..2993c2c --- /dev/null +++ b/corpus/arrays.txt @@ -0,0 +1,314 @@ +================================================================================ +Definite +================================================================================ + +package P is + type A is array (1 .. 2) of Boolean; + V : constant A := (1 => True, 2 => False); + V2 : constant A := (1 => True, others => False); +end P; + +-------------------------------------------------------------------------------- + +(compilation + (compilation_unit + (package_specification + (name + (identifier)) + (type_declaration + (full_type_declaration + (identifier) + (type_definition + (array_type_definition + (constrained_array_definition + (discrete_subtype_definition + (range_g + (simple_expression + (term + (factor + (primary + (numeric_literal))))) + (simple_expression + (term + (factor + (primary + (numeric_literal))))))) + (component_definition + (subtype_indication + (name + (identifier))))))))) + (object_declaration + (defining_identifier_list + (identifier)) + (subtype_indication + (name + (identifier))) + (assign_value + (expression + (relation + (simple_expression + (term + (factor + (primary + (aggregate + (array_aggregate + (named_array_aggregate + (array_component_association + (discrete_choice_list + (discrete_choice + (expression + (relation + (simple_expression + (term + (factor + (primary + (numeric_literal))))))))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier)))))))))) + (array_component_association + (discrete_choice_list + (discrete_choice + (expression + (relation + (simple_expression + (term + (factor + (primary + (numeric_literal))))))))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier))))))))))))))))))))) + (object_declaration + (defining_identifier_list + (identifier)) + (subtype_indication + (name + (identifier))) + (assign_value + (expression + (relation + (simple_expression + (term + (factor + (primary + (aggregate + (array_aggregate + (named_array_aggregate + (array_component_association + (discrete_choice_list + (discrete_choice + (expression + (relation + (simple_expression + (term + (factor + (primary + (numeric_literal))))))))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier)))))))))) + (array_component_association + (discrete_choice_list + (discrete_choice + (subtype_indication + (name + (identifier))))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier))))))))))))))))))))) + (name + (identifier))))) + +================================================================================ +Indefinite +================================================================================ + +package P is + type B is array (Natural range <>) of Boolean; + V : constant B := (1 .. 2 => False); +end P; + +-------------------------------------------------------------------------------- + +(compilation + (compilation_unit + (package_specification + (name + (identifier)) + (type_declaration + (full_type_declaration + (identifier) + (type_definition + (array_type_definition + (unconstrained_array_definition + (index_subtype_definition + (name + (identifier))) + (component_definition + (subtype_indication + (name + (identifier))))))))) + (object_declaration + (defining_identifier_list + (identifier)) + (subtype_indication + (name + (identifier))) + (assign_value + (expression + (relation + (simple_expression + (term + (factor + (primary + (aggregate + (array_aggregate + (named_array_aggregate + (array_component_association + (discrete_choice_list + (discrete_choice + (range_g + (simple_expression + (term + (factor + (primary + (numeric_literal))))) + (simple_expression + (term + (factor + (primary + (numeric_literal)))))))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier))))))))))))))))))))) + (name + (identifier))))) + +================================================================================ +2D +================================================================================ + +package P is + type C is array (Natural range <>, Integer range <>) of Boolean; + V : constant C := (1 .. 2 => (1 .. 2 => False)); +end P; + +-------------------------------------------------------------------------------- + +(compilation + (compilation_unit + (package_specification + (name + (identifier)) + (type_declaration + (full_type_declaration + (identifier) + (type_definition + (array_type_definition + (unconstrained_array_definition + (index_subtype_definition + (name + (identifier))) + (index_subtype_definition + (name + (identifier))) + (component_definition + (subtype_indication + (name + (identifier))))))))) + (object_declaration + (defining_identifier_list + (identifier)) + (subtype_indication + (name + (identifier))) + (assign_value + (expression + (relation + (simple_expression + (term + (factor + (primary + (aggregate + (array_aggregate + (named_array_aggregate + (array_component_association + (discrete_choice_list + (discrete_choice + (range_g + (simple_expression + (term + (factor + (primary + (numeric_literal))))) + (simple_expression + (term + (factor + (primary + (numeric_literal)))))))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (aggregate + (array_aggregate + (named_array_aggregate + (array_component_association + (discrete_choice_list + (discrete_choice + (range_g + (simple_expression + (term + (factor + (primary + (numeric_literal))))) + (simple_expression + (term + (factor + (primary + (numeric_literal)))))))) + (assoc_expression + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier)))))))))))))))))))))))))))))))) + (name + (identifier))))) diff --git a/grammar.js b/grammar.js index 8d092f9..22fa79a 100644 --- a/grammar.js +++ b/grammar.js @@ -588,12 +588,45 @@ module.exports = grammar({ $.enumeration_type_definition, $.integer_type_definition, $.real_type_definition, -// $.array_type_definition, + $.array_type_definition, // $.record_type_definition, // $.access_type_definition, $.derived_type_definition, // $.interface_type_definition, ), + array_type_definition: $ => choice( + $.unconstrained_array_definition, + $.constrained_array_definition, + ), + unconstrained_array_definition: $ => seq( + reservedWord('array'), + '(', + $._index_subtype_definition_list, + ')', + reservedWord('of'), + $.component_definition, + ), + constrained_array_definition: $ => seq( + reservedWord('array'), + '(', + $._discrete_subtype_definition_list, + ')', + reservedWord('of'), + $.component_definition, + ), + _discrete_subtype_definition_list: $ => + comma_separated_list_of($.discrete_subtype_definition), + discrete_subtype_definition: $ => choice( + $.subtype_indication, + $.range_g, + ), + _index_subtype_definition_list: $ => + comma_separated_list_of($.index_subtype_definition), + index_subtype_definition: $ => seq( + $.name, + reservedWord('range'), + '<>', + ), enumeration_type_definition: $ => seq( '(', $._enumeration_literal_list, @@ -696,7 +729,7 @@ module.exports = grammar({ $.defining_identifier_list, ':', $.component_definition, -// optional($.assign_value), + optional($.assign_value), optional($.aspect_specification), ';' ), @@ -804,6 +837,10 @@ module.exports = grammar({ reservedWord('with'), $.aspect_mark_list, ), + assign_value: $ => seq( + ':=', + $.expression, + ), at_clause: $ => seq( reservedWord('for'), $.identifier, @@ -1025,21 +1062,21 @@ module.exports = grammar({ $.defining_identifier_list, ';', reservedWord('constant'), -// $.assign_value, + $.assign_value, ';', ), object_declaration: $ => choice( seq( $.defining_identifier_list, ':', - reservedWord('aliased'), - reservedWord('constant'), + optional(reservedWord('aliased')), + optional(reservedWord('constant')), choice( $.subtype_indication, $.access_definition, -// $.array_type_definition, + $.array_type_definition, ), -// optional($.assign_value), + optional($.assign_value), optional($.aspect_specification), ';', ), @@ -1063,7 +1100,7 @@ module.exports = grammar({ optional($.non_empty_mode), optional($.null_exclusion), $.name, -// optional($.assign_value), + optional($.assign_value), ), parameter_specification_list: $ => list_of( ';',