From 184f9ca9b835ab169c93c17e81dc9dbbeae51ea6 Mon Sep 17 00:00:00 2001 From: Emmanuel Briot Date: Mon, 24 Oct 2022 14:48:54 +0200 Subject: [PATCH] support for discrete_range constraints --- corpus/types.txt | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ grammar.js | 6 ++++- 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/corpus/types.txt b/corpus/types.txt index 9e23242..b561896 100644 --- a/corpus/types.txt +++ b/corpus/types.txt @@ -256,3 +256,72 @@ end P; (numeric_literal)))))))))))))) (name (identifier))))) + +================================================================================ +Subtypes +================================================================================ + +package P is + subtype T is Integer range 1 .. 2; + subtype Arr is MyArray (1 .. 2, 3 .. 4); +end P; + +-------------------------------------------------------------------------------- + +(compilation + (compilation_unit + (package_specification + (name + (identifier)) + (subtype_declaration + (identifier) + (subtype_indication + (name + (identifier)) + (constraint + (scalar_constraint + (range_constraint + (range_g + (simple_expression + (term + (factor + (primary + (numeric_literal))))) + (simple_expression + (term + (factor + (primary + (numeric_literal))))))))))) + (subtype_declaration + (identifier) + (subtype_indication + (name + (identifier)) + (constraint + (index_constraint + (discrete_range + (range_g + (simple_expression + (term + (factor + (primary + (numeric_literal))))) + (simple_expression + (term + (factor + (primary + (numeric_literal))))))) + (discrete_range + (range_g + (simple_expression + (term + (factor + (primary + (numeric_literal))))) + (simple_expression + (term + (factor + (primary + (numeric_literal))))))))))) + (name + (identifier))))) diff --git a/grammar.js b/grammar.js index 81249e9..7970f32 100644 --- a/grammar.js +++ b/grammar.js @@ -730,7 +730,7 @@ module.exports = grammar({ ), index_constraint: $ => seq( '(', -// comma_separated_list_of($.discrete_range), + comma_separated_list_of($.discrete_range), ')', ), digits_constraint: $ => seq( @@ -875,6 +875,10 @@ module.exports = grammar({ $.subtype_indication, $.range_g, ), + discrete_range: $ => choice( // same as discrete_subtype_definition + $.subtype_indication, + $.range_g, + ), _index_subtype_definition_list: $ => comma_separated_list_of($.index_subtype_definition), index_subtype_definition: $ => seq(