Initial support for generics
This commit is contained in:
parent
59921871bb
commit
d440b2e820
117
corpus/generics.txt
Normal file
117
corpus/generics.txt
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
================================================================================
|
||||
generic package
|
||||
================================================================================
|
||||
|
||||
generic
|
||||
A : Integer := 1;
|
||||
type T (<>) is abstract tagged limited private or use My_Tagged;
|
||||
type I;
|
||||
with package Pro is new My_Pkg (F => 1, others => <>);
|
||||
with procedure Proc is null;
|
||||
with function Func return Boolean is <>;
|
||||
package P is
|
||||
pragma Compile_Time_Error (True, "an exception");
|
||||
end;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(generic_declaration
|
||||
(generic_package_declaration
|
||||
(generic_formal_part
|
||||
(generic_formal_parameter_declaration
|
||||
(formal_object_declaration
|
||||
(defining_identifier_list
|
||||
(identifier))
|
||||
(name
|
||||
(identifier))
|
||||
(assign_value
|
||||
(expression
|
||||
(relation
|
||||
(simple_expression
|
||||
(term
|
||||
(factor
|
||||
(primary
|
||||
(numeric_literal))))))))))
|
||||
(generic_formal_parameter_declaration
|
||||
(formal_type_declaration
|
||||
(formal_complete_type_declaration
|
||||
(identifier)
|
||||
(discriminant_part
|
||||
(unknown_discriminant_part))
|
||||
(formal_type_definition
|
||||
(formal_private_type_definition))
|
||||
(name
|
||||
(identifier)))))
|
||||
(generic_formal_parameter_declaration
|
||||
(formal_type_declaration
|
||||
(formal_incomplete_type_declaration
|
||||
(identifier))))
|
||||
(generic_formal_parameter_declaration
|
||||
(formal_package_declaration
|
||||
(identifier)
|
||||
(name
|
||||
(function_call
|
||||
(name
|
||||
(identifier))
|
||||
(actual_parameter_part
|
||||
(parameter_association
|
||||
(component_choice_list
|
||||
(selector_name
|
||||
(identifier)))
|
||||
(assoc_expression
|
||||
(expression
|
||||
(relation
|
||||
(simple_expression
|
||||
(term
|
||||
(factor
|
||||
(primary
|
||||
(numeric_literal)))))))))
|
||||
(parameter_association
|
||||
(component_choice_list
|
||||
(selector_name
|
||||
(identifier)))
|
||||
(assoc_expression)))))))
|
||||
(generic_formal_parameter_declaration
|
||||
(formal_subprogram_declaration
|
||||
(formal_concrete_subprogram_declaration
|
||||
(subprogram_specification
|
||||
(procedure_specification
|
||||
(name
|
||||
(identifier))))
|
||||
(subprogram_default))))
|
||||
(generic_formal_parameter_declaration
|
||||
(formal_subprogram_declaration
|
||||
(formal_concrete_subprogram_declaration
|
||||
(subprogram_specification
|
||||
(function_specification
|
||||
(name
|
||||
(identifier))
|
||||
(parameter_and_result_profile
|
||||
(result_profile
|
||||
(name
|
||||
(identifier))))))
|
||||
(subprogram_default)))))
|
||||
(package_specification
|
||||
(name
|
||||
(identifier))
|
||||
(pragma_g
|
||||
(identifier)
|
||||
(pragma_argument_association
|
||||
(expression
|
||||
(relation
|
||||
(simple_expression
|
||||
(term
|
||||
(factor
|
||||
(primary
|
||||
(name
|
||||
(identifier)))))))))
|
||||
(pragma_argument_association
|
||||
(expression
|
||||
(relation
|
||||
(simple_expression
|
||||
(term
|
||||
(factor
|
||||
(primary
|
||||
(string_literal))))))))))))))
|
||||
186
grammar.js
186
grammar.js
|
|
@ -108,6 +108,8 @@ module.exports = grammar({
|
|||
[$.function_call, $.procedure_call_statement],
|
||||
[$.function_call, $.name],
|
||||
[$.selector_name, $.primary],
|
||||
[$.formal_derived_type_definition],
|
||||
[$._direct_name, $.aspect_mark],
|
||||
|
||||
],
|
||||
|
||||
|
|
@ -337,10 +339,10 @@ module.exports = grammar({
|
|||
field('name', $.name),
|
||||
optional($.aspect_specification),
|
||||
reservedWord('is'),
|
||||
optional($._basic_declarative_item_list),
|
||||
repeat($._basic_declarative_item_pragma),
|
||||
optional(seq(
|
||||
reservedWord('private'),
|
||||
optional($._basic_declarative_item_list),
|
||||
repeat($._basic_declarative_item_pragma),
|
||||
)),
|
||||
reservedWord('end'),
|
||||
field('endname', optional($.name)),
|
||||
|
|
@ -726,9 +728,6 @@ module.exports = grammar({
|
|||
$.simple_expression,
|
||||
optional($.range_constraint),
|
||||
),
|
||||
_basic_declarative_item_list: $ => repeat1(
|
||||
$._basic_declarative_item_pragma,
|
||||
),
|
||||
_basic_declarative_item_pragma: $ => choice(
|
||||
$._basic_declarative_item,
|
||||
$.pragma_g,
|
||||
|
|
@ -1206,10 +1205,10 @@ module.exports = grammar({
|
|||
repeat($.generic_formal_parameter_declaration),
|
||||
),
|
||||
generic_formal_parameter_declaration: $ => choice(
|
||||
// $.formal_objet_declaration,
|
||||
// $.formal_type_declaration,
|
||||
// $.formal_subprogram_declaration,
|
||||
// $.formal_package_declaration,
|
||||
$.formal_object_declaration,
|
||||
$.formal_type_declaration,
|
||||
$.formal_subprogram_declaration,
|
||||
$.formal_package_declaration,
|
||||
$.use_clause,
|
||||
$.pragma_g,
|
||||
),
|
||||
|
|
@ -1242,6 +1241,166 @@ module.exports = grammar({
|
|||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
formal_object_declaration: $ => choice(
|
||||
seq(
|
||||
$.defining_identifier_list,
|
||||
':',
|
||||
optional($.non_empty_mode),
|
||||
optional($.null_exclusion),
|
||||
$.name,
|
||||
optional($.assign_value),
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
seq(
|
||||
$.defining_identifier_list,
|
||||
':',
|
||||
optional($.non_empty_mode),
|
||||
$.access_definition,
|
||||
optional($.assign_value),
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
),
|
||||
formal_type_declaration: $ => choice(
|
||||
$.formal_complete_type_declaration,
|
||||
$.formal_incomplete_type_declaration,
|
||||
),
|
||||
formal_complete_type_declaration: $ => seq(
|
||||
reservedWord('type'),
|
||||
$.identifier,
|
||||
optional($.discriminant_part),
|
||||
reservedWord('is'),
|
||||
$.formal_type_definition,
|
||||
optional(seq(
|
||||
reservedWord('or'),
|
||||
reservedWord('use'),
|
||||
$.name,
|
||||
)),
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
formal_incomplete_type_declaration: $ => seq(
|
||||
reservedWord('type'),
|
||||
$.identifier,
|
||||
optional($.discriminant_part),
|
||||
optional(seq(
|
||||
reservedWord('is'),
|
||||
reservedWord('tagged'),
|
||||
)),
|
||||
optional(seq(
|
||||
reservedWord('or'),
|
||||
reservedWord('use'),
|
||||
$.name,
|
||||
)),
|
||||
';',
|
||||
),
|
||||
formal_type_definition: $ => choice(
|
||||
$.formal_private_type_definition,
|
||||
$.formal_derived_type_definition,
|
||||
$.formal_discrete_type_definition,
|
||||
$.formal_signed_integer_type_definition,
|
||||
$.formal_modular_type_definition,
|
||||
$.formal_floating_point_definition,
|
||||
$.formal_ordinary_fixed_point_definition,
|
||||
$.formal_decimal_fixed_point_definition,
|
||||
$.formal_array_type_definition,
|
||||
$.formal_access_type_definition,
|
||||
$.formal_interface_type_definition,
|
||||
),
|
||||
formal_private_type_definition: $ => seq(
|
||||
optional(seq(
|
||||
optional(reservedWord('abstract')),
|
||||
reservedWord('tagged'),
|
||||
)),
|
||||
optional(reservedWord('limited')),
|
||||
reservedWord('private'),
|
||||
),
|
||||
formal_derived_type_definition: $ => seq(
|
||||
optional(reservedWord('abstract')),
|
||||
optional(choice(
|
||||
reservedWord('limited'),
|
||||
reservedWord('synchronized'),
|
||||
)),
|
||||
reservedWord('new'),
|
||||
$.name,
|
||||
optional(seq(
|
||||
optional(seq(
|
||||
reservedWord('and'),
|
||||
$.interface_list,
|
||||
)),
|
||||
reservedWord('with'),
|
||||
reservedWord('private'),
|
||||
)),
|
||||
),
|
||||
formal_discrete_type_definition: $ => seq(
|
||||
'(',
|
||||
'<>',
|
||||
')',
|
||||
),
|
||||
formal_signed_integer_type_definition: $ => seq(
|
||||
reservedWord('range'),
|
||||
'<>',
|
||||
),
|
||||
formal_modular_type_definition: $ => seq(
|
||||
reservedWord('mod'),
|
||||
'<>',
|
||||
),
|
||||
formal_floating_point_definition: $ => seq(
|
||||
reservedWord('digits'),
|
||||
'<>',
|
||||
),
|
||||
formal_ordinary_fixed_point_definition: $ => seq(
|
||||
reservedWord('delta'),
|
||||
'<>',
|
||||
),
|
||||
formal_decimal_fixed_point_definition: $ => seq(
|
||||
reservedWord('delta'),
|
||||
'<>',
|
||||
reservedWord('digits'),
|
||||
'<>',
|
||||
),
|
||||
formal_array_type_definition: $ => $.array_type_definition,
|
||||
formal_access_type_definition: $ => $.access_type_definition,
|
||||
formal_interface_type_definition: $ => $.interface_type_definition,
|
||||
formal_subprogram_declaration: $ => choice(
|
||||
$.formal_concrete_subprogram_declaration,
|
||||
$.formal_abstract_subprogram_declaration,
|
||||
),
|
||||
formal_concrete_subprogram_declaration: $ => seq(
|
||||
reservedWord('with'),
|
||||
$.subprogram_specification,
|
||||
optional(seq(
|
||||
reservedWord('is'),
|
||||
$.subprogram_default,
|
||||
)),
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
formal_abstract_subprogram_declaration: $ => seq(
|
||||
reservedWord('with'),
|
||||
$.subprogram_specification,
|
||||
reservedWord('is'),
|
||||
reservedWord('abstract'),
|
||||
optional($.subprogram_default),
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
subprogram_default: $ => choice(
|
||||
field('default_name', $.name),
|
||||
'<>',
|
||||
reservedWord('null'),
|
||||
),
|
||||
formal_package_declaration: $ => seq(
|
||||
reservedWord('with'),
|
||||
reservedWord('package'),
|
||||
$.identifier,
|
||||
reservedWord('is'),
|
||||
reservedWord('new'),
|
||||
$.name,
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
global_aspect_definition: $ => choice(
|
||||
seq(
|
||||
$.global_mode,
|
||||
|
|
@ -1364,13 +1523,20 @@ module.exports = grammar({
|
|||
optional(seq(
|
||||
'(',
|
||||
choice(
|
||||
// $.pragma_argument_association_list,
|
||||
comma_separated_list_of($.pragma_argument_association),
|
||||
$.conditional_quantified_expression,
|
||||
),
|
||||
')',
|
||||
)),
|
||||
';'
|
||||
),
|
||||
pragma_argument_association: $ => seq(
|
||||
optional(seq(
|
||||
$.aspect_mark,
|
||||
'=>',
|
||||
)),
|
||||
$.expression,
|
||||
),
|
||||
if_expression: $ => seq(
|
||||
reservedWord('if'),
|
||||
field('condition', $.expression),
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user