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
(primary
(numeric_literal)))))))))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))
(array_component_association
(discrete_choice_list
(discrete_choice
@ -82,15 +81,14 @@ end P;
(factor
(primary
(numeric_literal)))))))))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))))))))))
(object_declaration
(defining_identifier_list
(identifier))
@ -117,29 +115,103 @@ end P;
(factor
(primary
(numeric_literal)))))))))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))
(array_component_association
(discrete_choice_list
(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
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))))))))
(name
(identifier)))))
(numeric_literal)))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))))))))))))))
================================================================================
Indefinite
@ -200,15 +272,14 @@ end P;
(factor
(primary
(numeric_literal))))))))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))))))))))
(name
(identifier)))))
@ -274,38 +345,116 @@ end P;
(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))))))))))))))))))))))))))))))))
(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))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))))))))))))))))))))
(name
(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
(simple_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
(component_choice_list
(identifier))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))
(parameter_association
(component_choice_list
(identifier))
(assoc_expression)))))))
(identifier))))))))
(generic_formal_parameter_declaration
(formal_subprogram_declaration
(formal_concrete_subprogram_declaration

View File

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

View File

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

View File

@ -226,17 +226,15 @@ end F;
(aggregate
(record_aggregate
(record_component_association_list
(record_component_association
(component_choice_list
(identifier))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))
(handled_sequence_of_statements
(sequence_of_statements
(statement
@ -390,14 +388,13 @@ end;
(parameter_association
(component_choice_list
(identifier))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))))))))))))))))))))
================================================================================
if statement
@ -573,14 +570,13 @@ end;
(parameter_association
(component_choice_list
(identifier))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))))))))))))
(case_statement_alternative
(discrete_choice_list
(discrete_choice
@ -589,12 +585,14 @@ end;
(term
(factor
(primary
(character_literal)))))
(name
(character_literal))))))
(simple_expression
(term
(factor
(primary
(character_literal))))))))
(name
(character_literal)))))))))
(sequence_of_statements
(statement
(simple_statement
@ -608,7 +606,8 @@ end;
(term
(factor
(primary
(character_literal))))))))
(name
(character_literal)))))))))
(discrete_choice
(expression
(relation
@ -616,7 +615,8 @@ end;
(term
(factor
(primary
(character_literal)))))))))
(name
(character_literal))))))))))
(sequence_of_statements
(statement
(simple_statement
@ -684,27 +684,167 @@ end;
(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
(identifier))
(assoc_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))))))))))))))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(aggregate
(record_aggregate
(record_component_association_list
(component_choice_list
(identifier))
(expression
(relation
(simple_expression
(term
(factor
(primary
(numeric_literal))))))))))))))))))))))))))))))))))))
========
Filtered for loops
========
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
(name
(identifier)))))
(aggregate
(record_aggregate
(record_component_association_list
(record_component_association
(expression
(relation
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(membership_choice_list
(membership_choice
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(membership_choice_list
(membership_choice
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))))
(identifier)))))))))))))
================================================================================
Expression function declare
@ -286,37 +283,36 @@ function F2 (A : Integer) return Boolean
(result_profile
(name
(identifier)))))
(aggregate
(declare_expression
(declare_item
(object_declaration
(defining_identifier_list
(identifier))
(subtype_indication
(name
(identifier)))
(assign_value
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))
(binary_adding_operator)
(term
(factor
(primary
(numeric_literal))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))
(declare_expression
(declare_item
(object_declaration
(defining_identifier_list
(identifier))
(subtype_indication
(name
(identifier)))
(assign_value
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))
(binary_adding_operator)
(term
(factor
(primary
(numeric_literal))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))
================================================================================
Expression function raise
@ -337,15 +333,11 @@ function F3 return Boolean
(result_profile
(name
(identifier)))))
(aggregate
(record_aggregate
(record_component_association_list
(record_component_association
(expression
(relation
(raise_expression
(name
(identifier))))))))))))
(expression
(relation
(raise_expression
(name
(identifier))))))))
================================================================================
Expression function simple
@ -365,18 +357,14 @@ function F4 return Boolean is (True);
(result_profile
(name
(identifier)))))
(aggregate
(record_aggregate
(record_component_association_list
(record_component_association
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))
================================================================================
Expression function if
@ -404,52 +392,51 @@ function F (A : Integer) return Boolean
(result_profile
(name
(identifier)))))
(aggregate
(conditional_expression
(if_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(relational_operator)
(simple_expression
(term
(factor
(primary
(numeric_literal))))))
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(relational_operator)
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))))
(conditional_expression
(if_expression
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(relational_operator)
(simple_expression
(term
(factor
(primary
(numeric_literal))))))
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))
(relational_operator)
(simple_expression
(term
(factor
(primary
(numeric_literal)))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))
================================================================================
Expression function if extra parenthesis
@ -477,49 +464,44 @@ function F5 (A : Integer) return Boolean
(result_profile
(name
(identifier)))))
(aggregate
(record_aggregate
(record_component_association_list
(record_component_association
(expression
(relation
(simple_expression
(term
(factor
(primary
(aggregate
(conditional_expression
(if_expression
(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
(name
(identifier))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier))))))))))))))))))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(conditional_expression
(if_expression
(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
(name
(identifier))))))))
(expression
(relation
(simple_expression
(term
(factor
(primary
(name
(identifier)))))))))))))))))))
================================================================================
Expression function case
@ -527,7 +509,7 @@ Expression function case
function F (A : Integer) return Boolean
is (case A + 1 is
when 0 .. 1 | 3 .. 4 => True,
when 0 .. 1 | 3 .. 4 => True,
when others => False);
--------------------------------------------------------------------------------
@ -549,48 +531,8 @@ function F (A : Integer) return Boolean
(result_profile
(name
(identifier)))))
(aggregate
(conditional_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))))))))
(conditional_expression
(case_expression
(expression
(relation
(simple_expression
@ -598,18 +540,101 @@ function F (A : Integer) return Boolean
(factor
(primary
(name
(identifier)))))))))
(case_expression_alternative
(discrete_choice_list
(discrete_choice))
(expression
(relation
(simple_expression
(identifier)))))
(binary_adding_operator)
(term
(factor
(primary
(name
(identifier)))))))))))))))
(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
(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
@ -638,14 +663,12 @@ function F (A : My_Array) return Boolean
(result_profile
(name
(identifier)))))
(aggregate
(quantified_expression
(quantifier)
(iterator_specification
(identifier)
(name
(identifier)))
(assoc_expression
(quantified_expression
(quantifier)
(iterator_specification
(identifier)
(name
(identifier)))
(expression
(relation
(simple_expression
@ -659,7 +682,7 @@ function F (A : My_Array) return Boolean
(term
(factor
(primary
(numeric_literal)))))))))))))
(numeric_literal)))))))))))
================================================================================
Operators
@ -679,7 +702,8 @@ end "<";
(overriding_indicator)
(subprogram_specification
(function_specification
(string_literal)
(name
(string_literal))
(parameter_and_result_profile
(formal_part
(parameter_specification_list

View File

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

View File

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