various attempts to simplify grammar

Fixes handing of expression functions (for which the expression was
 identified as an aggregate)
Move conditional expressions out of 'aggregate', to conform with ARM and
 resolve the above amgiguity
Inline expression_list, which was resulting in a conflict with a
 record_component_association.
This commit is contained in:
Emmanuel Briot 2022-12-06 10:20:25 +01:00
parent 974160cf9b
commit 0a52f6df01
9 changed files with 1009 additions and 560 deletions

View File

@ -63,15 +63,14 @@ end P;
(factor (factor
(primary (primary
(numeric_literal))))))))) (numeric_literal)))))))))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier)))))))))
(identifier))))))))))
(array_component_association (array_component_association
(discrete_choice_list (discrete_choice_list
(discrete_choice (discrete_choice
@ -82,15 +81,14 @@ end P;
(factor (factor
(primary (primary
(numeric_literal))))))))) (numeric_literal)))))))))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier))))))))))))))))))))
(identifier)))))))))))))))))))))
(object_declaration (object_declaration
(defining_identifier_list (defining_identifier_list
(identifier)) (identifier))
@ -117,29 +115,103 @@ end P;
(factor (factor
(primary (primary
(numeric_literal))))))))) (numeric_literal)))))))))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier)))))))))
(identifier))))))))))
(array_component_association (array_component_association
(discrete_choice_list (discrete_choice_list
(discrete_choice)) (discrete_choice))
(assoc_expression (expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))))))))))
(name
(identifier)))))
================================================================================
Definite-2
================================================================================
package P is
type A is array (1 .. 3) of Boolean;
V : constant A := (1, 2, 3);
end;
--------------------------------------------------------------------------------
(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
(positional_array_aggregate
(expression (expression
(relation (relation
(simple_expression (simple_expression
(term (term
(factor (factor
(primary (primary
(name (numeric_literal)))))))
(identifier))))))))))))))))))))) (expression
(name (relation
(identifier))))) (simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))))))))))))))
================================================================================ ================================================================================
Indefinite Indefinite
@ -200,15 +272,14 @@ end P;
(factor (factor
(primary (primary
(numeric_literal)))))))) (numeric_literal))))))))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier))))))))))))))))))))
(identifier)))))))))))))))))))))
(name (name
(identifier))))) (identifier)))))
@ -274,38 +345,116 @@ end P;
(factor (factor
(primary (primary
(numeric_literal)))))))) (numeric_literal))))))))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (aggregate
(aggregate (array_aggregate
(array_aggregate (named_array_aggregate
(named_array_aggregate (array_component_association
(array_component_association (discrete_choice_list
(discrete_choice_list (discrete_choice
(discrete_choice (range_g
(range_g (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal)))))
(numeric_literal))))) (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal))))))))
(numeric_literal)))))))) (expression
(assoc_expression (relation
(expression (simple_expression
(relation (term
(simple_expression (factor
(term (primary
(factor (name
(primary (identifier))))))))))))))))))))))))))))))
(name
(identifier))))))))))))))))))))))))))))))))
(name (name
(identifier))))) (identifier)))))
=========
Index in array aggregates
=========
procedure P is
begin
Arr := (for Index in 1 .. Count => Function_Returning_Limited (Index));
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
(aggregate
(array_aggregate
(named_array_aggregate
(array_component_association
(iterated_element_association
(loop_parameter_specification
(identifier)
(discrete_subtype_definition
(range_g
(simple_expression
(term
(factor
(primary
(numeric_literal)))))
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(function_call
(name
(identifier))
(actual_parameter_part
(parameter_association
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))))))))))))))))))))))))))

View File

@ -87,3 +87,110 @@ end;
(statement (statement
(simple_statement (simple_statement
(null_statement))))))))))))) (null_statement)))))))))))))
================================================================================
Reduction
================================================================================
procedure P is
X : Integer :=
[parallel for Val of M when Val > 100.0 => (Val, 1)]
'Reduce("+", 0);
begin
null;
end;
--------------------------------------------------------------------------------
(compilation
(compilation_unit
(proper_body
(subprogram_body
(subprogram_specification
(procedure_specification
(name
(identifier))))
(non_empty_declarative_part
(declarative_item_pragma
(object_declaration
(defining_identifier_list
(identifier))
(subtype_indication
(name
(identifier)))
(assign_value
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(attribute_reference
(reduction_attribute_reference
(value_sequence
(iterated_element_association
(iterator_specification
(identifier)
(name
(identifier))
(iterator_filter
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(relational_operator)
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(aggregate
(array_aggregate
(positional_array_aggregate
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))
(tick)
(reduction_attribute_designator
(identifier)
(reduction_specification
(name
(string_literal))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))))))
(handled_sequence_of_statements
(sequence_of_statements
(statement
(simple_statement
(null_statement)))))))))

View File

@ -59,18 +59,16 @@ end;
(parameter_association (parameter_association
(component_choice_list (component_choice_list
(identifier)) (identifier))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal))))))))
(numeric_literal)))))))))
(parameter_association (parameter_association
(component_choice_list (component_choice_list
(identifier)) (identifier))))))))
(assoc_expression)))))))
(generic_formal_parameter_declaration (generic_formal_parameter_declaration
(formal_subprogram_declaration (formal_subprogram_declaration
(formal_concrete_subprogram_declaration (formal_concrete_subprogram_declaration

View File

@ -393,28 +393,24 @@ end;
(aggregate (aggregate
(record_aggregate (record_aggregate
(record_component_association_list (record_component_association_list
(record_component_association (component_choice_list
(component_choice_list (identifier))
(identifier)) (expression
(assoc_expression (relation
(expression (simple_expression
(relation (term
(simple_expression (factor
(term (primary
(factor (numeric_literal)))))))
(primary (component_choice_list
(numeric_literal))))))))) (identifier))
(record_component_association (expression
(component_choice_list (relation
(identifier)) (simple_expression
(assoc_expression (term
(expression (factor
(relation (primary
(simple_expression (numeric_literal))))))))))))))))))))))))))
(term
(factor
(primary
(numeric_literal))))))))))))))))))))))))))))
================================================================================ ================================================================================
record aggregate extension record aggregate extension
@ -460,17 +456,15 @@ end;
(name (name
(identifier)))))))) (identifier))))))))
(record_component_association_list (record_component_association_list
(record_component_association (component_choice_list
(component_choice_list (identifier))
(identifier)) (expression
(assoc_expression (relation
(expression (simple_expression
(relation (term
(simple_expression (factor
(term (primary
(factor (numeric_literal))))))))))))))))))))))))))
(primary
(numeric_literal))))))))))))))))))))))))))))
================================================================================ ================================================================================
record delta aggregate record delta aggregate
@ -517,14 +511,12 @@ end;
(name (name
(identifier)))))))) (identifier))))))))
(record_component_association_list (record_component_association_list
(record_component_association (component_choice_list
(component_choice_list (identifier))
(identifier)) (expression
(assoc_expression (relation
(expression (simple_expression
(relation (term
(simple_expression (factor
(term (primary
(factor (numeric_literal)))))))))))))))))))))))))))
(primary
(numeric_literal)))))))))))))))))))))))))))))

View File

@ -3,7 +3,7 @@ Renames object
================================================================================ ================================================================================
procedure P is procedure P is
Threshold renames Global_Threshold; Threshold renames With_Type_Inference;
A : Integer renames B; A : Integer renames B;
CE : exception renames Constraint_Error; CE : exception renames Constraint_Error;
package TIO renames Ada.Text_IO; package TIO renames Ada.Text_IO;

View File

@ -226,17 +226,15 @@ end F;
(aggregate (aggregate
(record_aggregate (record_aggregate
(record_component_association_list (record_component_association_list
(record_component_association
(component_choice_list (component_choice_list
(identifier)) (identifier))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal))))))))))))))))))
(numeric_literal))))))))))))))))))))
(handled_sequence_of_statements (handled_sequence_of_statements
(sequence_of_statements (sequence_of_statements
(statement (statement
@ -390,14 +388,13 @@ end;
(parameter_association (parameter_association
(component_choice_list (component_choice_list
(identifier)) (identifier))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal)))))))))))))))))))))))))))
(numeric_literal))))))))))))))))))))))))))))
================================================================================ ================================================================================
if statement if statement
@ -573,14 +570,13 @@ end;
(parameter_association (parameter_association
(component_choice_list (component_choice_list
(identifier)) (identifier))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal)))))))))))))))))
(numeric_literal))))))))))))))))))
(case_statement_alternative (case_statement_alternative
(discrete_choice_list (discrete_choice_list
(discrete_choice (discrete_choice
@ -589,12 +585,14 @@ end;
(term (term
(factor (factor
(primary (primary
(character_literal))))) (name
(character_literal))))))
(simple_expression (simple_expression
(term (term
(factor (factor
(primary (primary
(character_literal)))))))) (name
(character_literal)))))))))
(sequence_of_statements (sequence_of_statements
(statement (statement
(simple_statement (simple_statement
@ -608,7 +606,8 @@ end;
(term (term
(factor (factor
(primary (primary
(character_literal)))))))) (name
(character_literal)))))))))
(discrete_choice (discrete_choice
(expression (expression
(relation (relation
@ -616,7 +615,8 @@ end;
(term (term
(factor (factor
(primary (primary
(character_literal))))))))) (name
(character_literal))))))))))
(sequence_of_statements (sequence_of_statements
(statement (statement
(simple_statement (simple_statement
@ -684,27 +684,167 @@ end;
(name (name
(identifier)) (identifier))
(tick) (tick)
(aggregate (expression
(record_aggregate (relation
(record_component_association_list (simple_expression
(record_component_association (term
(expression (factor
(relation (primary
(simple_expression (aggregate
(term (record_aggregate
(factor (record_component_association_list
(primary (component_choice_list
(aggregate (identifier))
(record_aggregate (expression
(record_component_association_list (relation
(record_component_association (simple_expression
(component_choice_list (term
(identifier)) (factor
(assoc_expression (primary
(expression (numeric_literal))))))))))))))))))))))))))))))))))))
(relation
(simple_expression
(term ========
(factor Filtered for loops
(primary ========
(numeric_literal))))))))))))))))))))))))))))))))))))))))))
procedure P is
begin
for E of Some_Array when E /= 0 loop
null;
end loop;
end;
-------
(compilation
(compilation_unit
(proper_body
(subprogram_body
(subprogram_specification
(procedure_specification
(name
(identifier))))
(handled_sequence_of_statements
(sequence_of_statements
(statement
(compound_statement
(loop_statement
(iteration_scheme
(iterator_specification
(identifier)
(name
(identifier))
(iterator_filter
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(relational_operator)
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))
(sequence_of_statements
(statement
(simple_statement
(null_statement)))))))))))))
=======
Assignment target name
=======
procedure P is
begin
Some_Very_Long.And_Complex (Expression) := @ + 1;
Another_Very_Long.And_Complex (Expression) := Function_Call (@);
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
(function_call
(name
(identifier)
(name
(identifier)))
(actual_parameter_part
(parameter_association
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))
(assign_value
(expression
(relation
(simple_expression
(term
(factor
(primary
(name))))
(binary_adding_operator)
(term
(factor
(primary
(numeric_literal)))))))))))
(statement
(simple_statement
(assignment_statement
(name
(function_call
(name
(identifier)
(name
(identifier)))
(actual_parameter_part
(parameter_association
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))
(assign_value
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(function_call
(name
(identifier))
(actual_parameter_part
(parameter_association
(expression
(relation
(simple_expression
(term
(factor
(primary
(name)))))))))))))))))))))))))))

View File

@ -239,26 +239,23 @@ function F2 (A : Integer) return Boolean
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (expression
(record_aggregate (relation
(record_component_association_list (simple_expression
(record_component_association (term
(expression (factor
(relation (primary
(name
(identifier))))))
(membership_choice_list
(membership_choice
(simple_expression (simple_expression
(term (term
(factor (factor
(primary (primary
(name (name
(identifier)))))) (identifier)))))))))))))
(membership_choice_list
(membership_choice
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))))
================================================================================ ================================================================================
Expression function declare Expression function declare
@ -286,37 +283,36 @@ function F2 (A : Integer) return Boolean
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (declare_expression
(declare_expression (declare_item
(declare_item (object_declaration
(object_declaration (defining_identifier_list
(defining_identifier_list (identifier))
(identifier)) (subtype_indication
(subtype_indication (name
(name (identifier)))
(identifier))) (assign_value
(assign_value (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier)))))
(identifier))))) (binary_adding_operator)
(binary_adding_operator) (term
(term (factor
(factor (primary
(primary (numeric_literal))))))))))
(numeric_literal)))))))))) (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier))))))))))))
(identifier)))))))))))))
================================================================================ ================================================================================
Expression function raise Expression function raise
@ -337,15 +333,11 @@ function F3 return Boolean
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (expression
(record_aggregate (relation
(record_component_association_list (raise_expression
(record_component_association (name
(expression (identifier))))))))
(relation
(raise_expression
(name
(identifier))))))))))))
================================================================================ ================================================================================
Expression function simple Expression function simple
@ -365,18 +357,14 @@ function F4 return Boolean is (True);
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (expression
(record_aggregate (relation
(record_component_association_list (simple_expression
(record_component_association (term
(expression (factor
(relation (primary
(simple_expression (name
(term (identifier)))))))))))
(factor
(primary
(name
(identifier)))))))))))))))
================================================================================ ================================================================================
Expression function if Expression function if
@ -404,52 +392,51 @@ function F (A : Integer) return Boolean
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (conditional_expression
(conditional_expression (if_expression
(if_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier))))))
(identifier)))))) (relational_operator)
(relational_operator) (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal))))))
(numeric_literal)))))) (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier))))))
(identifier)))))) (relational_operator)
(relational_operator) (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal)))))))
(numeric_literal))))))) (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier))))))))
(identifier)))))))) (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (name
(name (identifier)))))))))))))
(identifier))))))))))))))
================================================================================ ================================================================================
Expression function if extra parenthesis Expression function if extra parenthesis
@ -477,49 +464,44 @@ function F5 (A : Integer) return Boolean
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (expression
(record_aggregate (relation
(record_component_association_list (simple_expression
(record_component_association (term
(expression (factor
(relation (primary
(simple_expression (conditional_expression
(term (if_expression
(factor (expression
(primary (relation
(aggregate (simple_expression
(conditional_expression (term
(if_expression (factor
(expression (primary
(relation (name
(simple_expression (identifier))))))
(term (relational_operator)
(factor (simple_expression
(primary (term
(name (factor
(identifier)))))) (primary
(relational_operator) (numeric_literal)))))))
(simple_expression (expression
(term (relation
(factor (simple_expression
(primary (term
(numeric_literal))))))) (factor
(expression (primary
(relation (name
(simple_expression (identifier))))))))
(term (expression
(factor (relation
(primary (simple_expression
(name (term
(identifier)))))))) (factor
(expression (primary
(relation (name
(simple_expression (identifier)))))))))))))))))))
(term
(factor
(primary
(name
(identifier))))))))))))))))))))))))
================================================================================ ================================================================================
Expression function case Expression function case
@ -527,7 +509,7 @@ Expression function case
function F (A : Integer) return Boolean function F (A : Integer) return Boolean
is (case A + 1 is is (case A + 1 is
when 0 .. 1 | 3 .. 4 => True, when 0 .. 1 | 3 .. 4 => True,
when others => False); when others => False);
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -549,48 +531,8 @@ function F (A : Integer) return Boolean
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (conditional_expression
(conditional_expression (case_expression
(case_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))
(binary_adding_operator)
(term
(factor
(primary
(numeric_literal)))))))
(case_expression_alternative
(discrete_choice_list
(discrete_choice
(range_g
(simple_expression
(term
(factor
(primary
(numeric_literal)))))
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(discrete_choice
(range_g
(simple_expression
(term
(factor
(primary
(numeric_literal)))))
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))
(expression (expression
(relation (relation
(simple_expression (simple_expression
@ -598,18 +540,101 @@ function F (A : Integer) return Boolean
(factor (factor
(primary (primary
(name (name
(identifier))))))))) (identifier)))))
(case_expression_alternative (binary_adding_operator)
(discrete_choice_list
(discrete_choice))
(expression
(relation
(simple_expression
(term (term
(factor (factor
(primary (primary
(name (numeric_literal)))))))
(identifier))))))))))))))) (case_expression_alternative
(discrete_choice_list
(discrete_choice
(range_g
(simple_expression
(term
(factor
(primary
(numeric_literal)))))
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(discrete_choice
(range_g
(simple_expression
(term
(factor
(primary
(numeric_literal)))))
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))
(case_expression_alternative
(discrete_choice_list
(discrete_choice))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))))
================================================================================
Expression function array
================================================================================
function F return My_Array is (1 .. 2 => True);
------
(compilation
(compilation_unit
(expression_function_declaration
(function_specification
(name
(identifier))
(parameter_and_result_profile
(result_profile
(name
(identifier)))))
(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))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))
================================================================================ ================================================================================
Expression function quantified Expression function quantified
@ -638,14 +663,12 @@ function F (A : My_Array) return Boolean
(result_profile (result_profile
(name (name
(identifier))))) (identifier)))))
(aggregate (quantified_expression
(quantified_expression (quantifier)
(quantifier) (iterator_specification
(iterator_specification (identifier)
(identifier) (name
(name (identifier)))
(identifier)))
(assoc_expression
(expression (expression
(relation (relation
(simple_expression (simple_expression
@ -659,7 +682,7 @@ function F (A : My_Array) return Boolean
(term (term
(factor (factor
(primary (primary
(numeric_literal))))))))))))) (numeric_literal)))))))))))
================================================================================ ================================================================================
Operators Operators
@ -679,7 +702,8 @@ end "<";
(overriding_indicator) (overriding_indicator)
(subprogram_specification (subprogram_specification
(function_specification (function_specification
(string_literal) (name
(string_literal))
(parameter_and_result_profile (parameter_and_result_profile
(formal_part (formal_part
(parameter_specification_list (parameter_specification_list

View File

@ -232,28 +232,32 @@ end P;
(primary (primary
(name (name
(identifier)))))))))) (identifier))))))))))
(assoc_expression (expression
(expression (relation
(relation (simple_expression
(simple_expression (term
(term (factor
(factor (primary
(primary (numeric_literal))))))))
(numeric_literal)))))))))
(array_component_association (array_component_association
(discrete_choice_list (discrete_choice_list
(discrete_choice (discrete_choice
(subtype_indication (expression
(name (relation
(identifier))))) (simple_expression
(assoc_expression (term
(expression (factor
(relation (primary
(simple_expression (name
(term (identifier))))))))))
(factor
(primary (expression
(numeric_literal)))))))))))))) (relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))))))
(name (name
(identifier))))) (identifier)))))

View File

@ -2,7 +2,7 @@
* A case-insensitive keyword (copied from VHDL grammar) * A case-insensitive keyword (copied from VHDL grammar)
*/ */
const reservedWord = word => const reservedWord = word =>
//word || // when debugging conflict error msgs // word || // when debugging conflict error msgs
alias(reserved(caseInsensitive(word)), word) alias(reserved(caseInsensitive(word)), word)
; ;
const reserved = regex => token(prec(2, new RegExp(regex))); const reserved = regex => token(prec(2, new RegExp(regex)));
@ -54,8 +54,11 @@ module.exports = grammar({
// ??? Invalid Ada // ??? Invalid Ada
[$.name, $.component_choice_list], [$.name, $.component_choice_list],
// name ':=' '(' expression . ',' ... // 'case' '(' expression . ',' ...
[$.expression_list, $.record_component_association], [$.record_component_association_list, $.positional_array_aggregate],
// 'case' '[' iterated_element_association . ']'
[$.value_sequence, $.array_component_association],
// "procedure name is" could be either a procedure specification, or // "procedure name is" could be either a procedure specification, or
// a generic_instantiation. // a generic_instantiation.
@ -66,11 +69,6 @@ module.exports = grammar({
[$.attribute_definition_clause, $.attribute_reference], [$.attribute_definition_clause, $.attribute_reference],
// identifier '.' name . '''
// Could be either identifier '.' (attribute_reference name . tick
// or (name identifier '.' name) . '''
[$.name, $.attribute_reference],
// identifier . ':' ... // identifier . ':' ...
[$.defining_identifier_list, $.object_renaming_declaration, [$.defining_identifier_list, $.object_renaming_declaration,
$.exception_renaming_declaration], $.exception_renaming_declaration],
@ -87,27 +85,18 @@ module.exports = grammar({
// an aspect_specification. // an aspect_specification.
[$.derived_type_definition], [$.derived_type_definition],
// 'for' name 'use' '(' name . '=>' ...
// The name could either be from a primary or a subtype_indication.
[$.subtype_indication, $.primary],
// 'for' name 'use' '(' 'for' identifier 'in' name . 'use' // 'for' name 'use' '(' 'for' identifier 'in' name . 'use'
[$.iterator_specification, $.subtype_indication], [$.iterator_specification, $.subtype_indication],
// 'type' identifier 'is' 'mod' 'raise' name . 'with' ...
// ??? This appears legal Ada per the grammar, but doesn't make sense.
// ??? This results in a large slowdown of the parser
[$.raise_expression],
// 'type' identifier known_discriminant_part . 'is' ... // 'type' identifier known_discriminant_part . 'is' ...
[$.full_type_declaration, $.discriminant_part], [$.full_type_declaration, $.discriminant_part],
// 'type' identifier 'is' 'new' subtype_indication . 'with' . // 'type' identifier 'is' 'new' subtype_indication . 'with' .
[$.private_extension_declaration, $.derived_type_definition], [$.private_extension_declaration, $.derived_type_definition],
// subprogram_specification // subprogram_specification 'is' 'begin'
// 'with' aspect_mark '=>' 'do' name '(' name . ')' // handled_sequence_of_statements 'end' string_literal . ';'
[$.primary, $.dispatching_operation_specifier], [$.name, $.subprogram_body],
[$.function_call, $.procedure_call_statement], [$.function_call, $.procedure_call_statement],
[$.function_call, $.name], [$.function_call, $.name],
@ -155,9 +144,10 @@ module.exports = grammar({
$.qualified_expression, $.qualified_expression,
'@', '@',
//$.explicit_dereference, // covered by the first rule above //$.explicit_dereference, // covered by the first rule above
//$.character_literal, // from adamode, seems wrong. $.character_literal,
//$.string_literal, // from ada-mode, but seems wrong. $.string_literal, // name of an operator. However, in a
// // Added to primary instead // number of places using a string doesn't
// make sense.
), ),
name_list: $ => comma_separated_list_of($.name), name_list: $ => comma_separated_list_of($.name),
defining_identifier_list: $ => comma_separated_list_of($.identifier), defining_identifier_list: $ => comma_separated_list_of($.identifier),
@ -168,13 +158,13 @@ module.exports = grammar({
$.tick, $.tick,
$.attribute_designator, $.attribute_designator,
), ),
// $.reduction_attribute_reference, $.reduction_attribute_reference,
),
reduction_attribute_reference: $ => seq(
$.value_sequence,
$.tick,
$.reduction_attribute_designator,
), ),
// reduction_attribute_reference: $ => seq(
// $.value_sequence,
// $.tick,
// $.reduction_attribute_designator,
// ),
reduction_attribute_designator: $ => seq( reduction_attribute_designator: $ => seq(
$.identifier, $.identifier,
'(', '(',
@ -186,19 +176,19 @@ module.exports = grammar({
',', ',',
$.expression, $.expression,
), ),
// value_sequence: $ => seq( value_sequence: $ => seq(
// '[', '[',
// optional(seq( optional(seq(
// field('is_parallel', reservedWord('parallel')), field('is_parallel', reservedWord('parallel')),
// optional(seq( optional(seq(
// '(', '(',
// $.chunk_specification, $.chunk_specification,
// ')', ')',
// )), )),
// )), )),
// $.iterated_element_association, $.iterated_element_association,
// ']', ']',
// ), ),
chunk_specification: $ => choice( chunk_specification: $ => choice(
$.simple_expression, $.simple_expression,
seq( seq(
@ -207,7 +197,7 @@ module.exports = grammar({
$.discrete_subtype_definition, $.discrete_subtype_definition,
), ),
), ),
iterated_element_association: $ => seq( iterated_element_association: $ => seq( // RM 4.3.5
reservedWord('for'), reservedWord('for'),
choice( choice(
$.loop_parameter_specification, $.loop_parameter_specification,
@ -217,7 +207,8 @@ module.exports = grammar({
reservedWord('use'), reservedWord('use'),
$.expression, $.expression,
)), )),
$.assoc_expression, '=>',
$.expression,
), ),
discrete_subtype_definition: $ => choice( discrete_subtype_definition: $ => choice(
$.subtype_indication, $.subtype_indication,
@ -238,7 +229,7 @@ module.exports = grammar({
reservedWord('when'), reservedWord('when'),
field('condition', $.expression), field('condition', $.expression),
), ),
iterator_specification: $ => seq( iterator_specification: $ => seq( // ARM 5.5.2
$.identifier, $.identifier,
optional(seq( optional(seq(
':', ':',
@ -263,10 +254,13 @@ module.exports = grammar({
$.name, $.name,
$.actual_parameter_part, $.actual_parameter_part,
), ),
qualified_expression: $ => seq( qualified_expression: $ => seq( // ARM 4.7
$.name, $.name,
$.tick, $.tick,
$.aggregate, choice(
seq('(', $.expression, ')'),
$.aggregate,
),
), ),
compilation_unit: $ => choice( compilation_unit: $ => choice(
$.with_clause, $.with_clause,
@ -378,9 +372,9 @@ module.exports = grammar({
optional($.name), optional($.name),
';', ';',
), ),
subtype_indication: $ => seq( subtype_indication: $ => seq( // ARM 3.2.2
optional($.null_exclusion), optional($.null_exclusion),
$.name, field('subtype_mark', $.name),
optional($.constraint), optional($.constraint),
), ),
constraint: $ => choice( constraint: $ => choice(
@ -416,25 +410,14 @@ module.exports = grammar({
reservedWord('range'), reservedWord('range'),
$.range_g, $.range_g,
), ),
expression_list: $ => prec.left(
comma_separated_list_of($.expression),
),
expression: $ => choice( expression: $ => choice(
list_of(reservedWord('and'), $.relation), list_of(seq(reservedWord('and'), optional(reservedWord('then'))),
list_of(seq(reservedWord('and'), reservedWord('then')), $.relation), $.relation),
list_of(reservedWord('or'), $.relation), list_of(seq(reservedWord('or'), optional(reservedWord('else'))),
list_of(seq(reservedWord('or'), reservedWord('else')), $.relation), $.relation),
list_of(reservedWord('xor'), $.relation), list_of(reservedWord('xor'), $.relation),
), ),
assoc_expression: $ => choice( relation: $ => choice( // RM 4.4
seq('=>', '<>'),
$._non_default_assoc_expression,
),
_non_default_assoc_expression: $ => seq(
'=>',
$.expression,
),
relation: $ => choice(
seq( seq(
$.simple_expression, $.simple_expression,
optional(seq( optional(seq(
@ -448,16 +431,16 @@ module.exports = grammar({
reservedWord('in'), reservedWord('in'),
$.membership_choice_list, $.membership_choice_list,
), ),
$.raise_expression, $.raise_expression, // Added Ada 20x
), ),
raise_expression: $ => seq( raise_expression: $ => prec.right(1, seq(
reservedWord('raise'), reservedWord('raise'),
$.name, $.name,
optional(seq( optional(seq(
reservedWord('with'), reservedWord('with'),
$.simple_expression, $.simple_expression,
)), )),
), )),
membership_choice_list: $ => prec.right( membership_choice_list: $ => prec.right(
list_of('|', $.membership_choice), list_of('|', $.membership_choice),
), ),
@ -497,15 +480,31 @@ module.exports = grammar({
$.primary, $.primary,
), ),
), ),
primary: $ => choice(
_parenthesized_expression: $ => seq(
'(',
choice(
$.expression,
$.conditional_expression,
$.quantified_expression,
$.declare_expression,
),
')',
),
// primary might resolve as an 'aggregate', which might resolve as
// a 'position_array_aggregate', so an expression like
// case ( .. )
// is ambiguous. So we raise the priority here.
primary: $ => prec(2, choice( // RM 4.4
$.numeric_literal, $.numeric_literal,
reservedWord('null'), reservedWord('null'),
$.string_literal, // ada-mode puts this in name instead
$.aggregate, $.aggregate,
$.name, $.name,
$.string_literal, // ada-mode puts this in name instead
$.character_literal,
$.allocator, $.allocator,
), $._parenthesized_expression,
)),
allocator: $ => seq( allocator: $ => seq(
reservedWord('new'), reservedWord('new'),
optional($.subpool_specification), optional($.subpool_specification),
@ -575,20 +574,32 @@ module.exports = grammar({
'(', '(',
choice( choice(
comma_separated_list_of($.parameter_association), comma_separated_list_of($.parameter_association),
// Those are not in the ARM, but added here for generic
// instantiations, which get the actual parameter part via $.name
// and its $.function_call
// ????
$.conditional_expression, $.conditional_expression,
$.quantified_expression, $.quantified_expression,
$.declare_expression, $.declare_expression,
), ),
')', ')',
), ),
// RM 6.4, but this one also handles parameters for generic
// instantiations.
parameter_association: $ => choice( parameter_association: $ => choice(
seq( seq(
$.component_choice_list, $.component_choice_list,
$.assoc_expression, '=>',
choice(
$.expression,
'<>',
),
), ),
$.expression, $.expression,
'<>', '<>',
), ),
conditional_expression: $ => choice( conditional_expression: $ => choice(
$.if_expression, $.if_expression,
$.case_expression, $.case_expression,
@ -598,14 +609,15 @@ module.exports = grammar({
$.case_expression, $.case_expression,
$.quantified_expression, $.quantified_expression,
), ),
quantified_expression: $ => seq( quantified_expression: $ => seq( // ARM 4.5.8
reservedWord('for'), reservedWord('for'),
$.quantifier, $.quantifier,
choice( choice(
$.loop_parameter_specification, $.loop_parameter_specification,
$.iterator_specification, $.iterator_specification,
), ),
$.assoc_expression, '=>',
field('predicate', $.expression),
), ),
declare_expression: $ => seq( declare_expression: $ => seq(
reservedWord('declare'), reservedWord('declare'),
@ -621,33 +633,25 @@ module.exports = grammar({
reservedWord('all'), reservedWord('all'),
reservedWord('some'), reservedWord('some'),
), ),
case_expression: $ => seq( case_expression: $ => seq( // RM 4.5.7
reservedWord('case'), reservedWord('case'),
$.expression, $.expression,
reservedWord('is'), reservedWord('is'),
comma_separated_list_of($.case_expression_alternative), comma_separated_list_of($.case_expression_alternative),
), ),
case_expression_alternative: $ => seq( case_expression_alternative: $ => seq( // RM 4.5.7
reservedWord('when'), reservedWord('when'),
$.discrete_choice_list, $.discrete_choice_list,
$._non_default_assoc_expression, '=>',
$.expression,
), ),
component_choice_list: $ => component_choice_list: $ =>
list_of('|', $.identifier), list_of('|', $.identifier),
aggregate: $ => choice( aggregate: $ => choice( // RM 4.3
$.record_aggregate, $.record_aggregate,
$.extension_aggregate, $.extension_aggregate,
$.array_aggregate, $.array_aggregate,
$.delta_aggregate, $.delta_aggregate, // Ada 20x
seq(
'(',
choice(
$.conditional_expression,
$.quantified_expression,
$.declare_expression,
),
')',
),
), ),
delta_aggregate: $ => choice( delta_aggregate: $ => choice(
$.record_delta_aggregate, $.record_delta_aggregate,
@ -674,7 +678,7 @@ module.exports = grammar({
$.expression, $.expression,
reservedWord('with'), reservedWord('with'),
reservedWord('delta'), reservedWord('delta'),
$.array_component_association_list, $._array_component_association_list,
')', ')',
), ),
seq( seq(
@ -682,7 +686,7 @@ module.exports = grammar({
$.expression, $.expression,
reservedWord('with'), reservedWord('with'),
reservedWord('delta'), reservedWord('delta'),
$.array_component_association_list, $._array_component_association_list,
']', ']',
), ),
), ),
@ -691,25 +695,34 @@ module.exports = grammar({
$.record_component_association_list, $.record_component_association_list,
')', ')',
), ),
array_component_association: $ => seq(
$.discrete_choice_list, // Either:
$.assoc_expression, // * 'null record'
), // * expression, {expression_or_named}
array_component_association_list: $ => // expression_or_named:: expression | choice => expression
comma_separated_list_of($.array_component_association), // * named {, named}
record_component_association: $ => choice(
seq(
$.component_choice_list,
$.assoc_expression,
),
$.expression,
),
record_component_association_list: $ => choice( record_component_association_list: $ => choice(
comma_separated_list_of($.record_component_association),
seq( seq(
reservedWord('null'), reservedWord('null'),
reservedWord('record'), reservedWord('record'),
), ),
seq(
$.expression,
',', // Need at least two components with positional
comma_separated_list_of(choice(
$.expression,
$._named_record_component_association,
)),
),
comma_separated_list_of($._named_record_component_association),
),
_named_record_component_association: $ => seq( // adapted from ARM 4.3.1
$.component_choice_list,
'=>',
choice(
$.expression,
'<>',
),
), ),
null_exclusion: $ => seq( null_exclusion: $ => seq(
reservedWord('not'), reservedWord('not'),
@ -1017,24 +1030,37 @@ module.exports = grammar({
$.null_array_aggregate, $.null_array_aggregate,
$.named_array_aggregate, $.named_array_aggregate,
), ),
positional_array_aggregate: $ => choice( positional_array_aggregate: $ => choice( // 4.3.3
seq( seq(
'(', '(',
$.expression_list, $.expression,
optional(seq( ',',
',', prec.left(1, comma_separated_list_of($.expression)),
reservedWord('others'), ')',
$.assoc_expression, ),
)), seq(
'(',
comma_separated_list_of($.expression),
',',
reservedWord('others'),
'=>',
choice(
$.expression,
'<>',
),
')', ')',
), ),
seq( seq(
'[', '[',
$.expression_list, comma_separated_list_of($.expression),
optional(seq( optional(seq(
',', ',',
reservedWord('others'), reservedWord('others'),
$.assoc_expression, '=>',
choice(
$.expression,
'<>',
),
)), )),
']', ']',
), ),
@ -1044,28 +1070,24 @@ module.exports = grammar({
']', ']',
), ),
named_array_aggregate: $ => choice( named_array_aggregate: $ => choice(
seq( seq('(', $._array_component_association_list, ')'),
'(', seq('[', $._array_component_association_list, ']'),
$._array_component_association_list,
')',
),
seq(
'[',
$._array_component_association_list,
']',
),
), ),
_array_component_association_list: $ => _array_component_association_list: $ =>
comma_separated_list_of($.array_component_association), comma_separated_list_of($.array_component_association),
array_component_association: $ => choice( array_component_association: $ => choice( // ARM 4.3.3
seq( seq(
$.discrete_choice_list, $.discrete_choice_list,
$.assoc_expression, '=>',
choice(
$.expression,
'<>',
),
), ),
$.iterated_element_association, $.iterated_element_association,
), ),
discrete_choice_list: $ => list_of('|', $.discrete_choice), discrete_choice_list: $ => list_of('|', $.discrete_choice),
discrete_choice: $ => choice( discrete_choice: $ => choice( // ARM 3.8.1
$.expression, $.expression,
$.subtype_indication, $.subtype_indication,
$.range_g, $.range_g,
@ -1296,7 +1318,7 @@ module.exports = grammar({
reservedWord('in'), reservedWord('in'),
$.discrete_subtype_definition, $.discrete_subtype_definition,
), ),
enumeration_aggregate: $ => $.array_aggregate, // ??? inline enumeration_aggregate: $ => $.array_aggregate, // ??? inline ARM 13.4
enumeration_representation_clause: $ => seq( enumeration_representation_clause: $ => seq(
reservedWord('for'), reservedWord('for'),
$.name, $.name,
@ -1337,10 +1359,7 @@ module.exports = grammar({
), ),
function_specification: $ => seq( function_specification: $ => seq(
reservedWord('function'), reservedWord('function'),
choice( $.name,
$.name,
$.string_literal, // for operators
),
$.parameter_and_result_profile, $.parameter_and_result_profile,
), ),
generic_declaration: $ => choice( generic_declaration: $ => choice(
@ -1372,19 +1391,27 @@ module.exports = grammar({
), ),
generic_instantiation: $ => seq( generic_instantiation: $ => seq(
choice( choice(
reservedWord('package'), seq(
reservedWord('package'),
$.name,
),
seq( seq(
optional($.overriding_indicator), optional($.overriding_indicator),
choice( choice(
reservedWord('procedure'), seq(
reservedWord('function'), reservedWord('procedure'),
$.name,
),
seq(
reservedWord('function'),
$.name,
),
), ),
), ),
), ),
$.name,
reservedWord('is'), reservedWord('is'),
reservedWord('new'), reservedWord('new'),
$.name, // includes the generic_actual_part $.name, // includes the generic_actual_part (via the function call)
optional($.aspect_specification), optional($.aspect_specification),
';', ';',
), ),
@ -2162,7 +2189,7 @@ module.exports = grammar({
$.access_definition, $.access_definition,
), ),
procedure_call_statement: $ => seq( procedure_call_statement: $ => seq(
$.name, $.name, // not an operator
optional($.actual_parameter_part), optional($.actual_parameter_part),
';', ';',
), ),
@ -2233,11 +2260,19 @@ module.exports = grammar({
optional($.aspect_specification), optional($.aspect_specification),
';', ';',
), ),
expression_function_declaration: $ => seq( expression_function_declaration: $ => seq( // RM 6.8
optional($.overriding_indicator), optional($.overriding_indicator),
$.function_specification, $.function_specification,
reservedWord('is'), reservedWord('is'),
$.aggregate, choice(
$.aggregate, // Ada 20x
// In the RM grammar, this is a simple '(expression)', but
// conditional expression would require a second nested pair of
// parenthesis, whereas this is not mandatory anymore in the
// text of the RM.
$._parenthesized_expression,
),
optional($.aspect_specification), optional($.aspect_specification),
';', ';',
), ),