Fix error for access parameters and untyped constants

This commit is contained in:
Emmanuel Briot 2022-12-09 14:38:08 +01:00
parent 3b5200c14c
commit 7bd8543b71
12 changed files with 29498 additions and 29375 deletions

View File

@ -570,7 +570,7 @@ module.exports = grammar({
seq(
optional(reservedWord('protected')),
reservedWord('procedure'),
optional($._non_empty_parameter_profile),
optional($.formal_part),
),
seq(
optional(reservedWord('protected')),
@ -852,28 +852,19 @@ module.exports = grammar({
$.enumeration_type_definition,
$._integer_type_definition,
$._real_type_definition,
$._array_type_definition,
$.array_type_definition,
$.record_type_definition,
$._access_type_definition,
$.derived_type_definition,
$.interface_type_definition,
),
_array_type_definition: $ => choice(
$.unconstrained_array_definition,
$.constrained_array_definition,
),
unconstrained_array_definition: $ => seq(
reservedWord('array'),
'(',
$._index_subtype_definition_list,
')',
reservedWord('of'),
$.component_definition,
),
constrained_array_definition: $ => seq(
array_type_definition: $ => seq( // merges constrained and unconstrained
reservedWord('array'),
'(',
choice(
$._discrete_subtype_definition_list,
$._index_subtype_definition_list,
),
')',
reservedWord('of'),
$.component_definition,
@ -1302,7 +1293,7 @@ module.exports = grammar({
$._discrete_subtype_definition,
')',
)),
optional($._non_empty_parameter_profile),
optional($.formal_part),
optional($.aspect_specification),
';',
),
@ -1366,7 +1357,7 @@ module.exports = grammar({
)),
formal_part: $ => seq(
'(',
$.parameter_specification_list,
$._parameter_specification_list,
')',
),
function_specification: $ => seq(
@ -1546,7 +1537,7 @@ module.exports = grammar({
reservedWord('digits'),
'<>',
),
formal_array_type_definition: $ => $._array_type_definition,
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(
@ -1668,7 +1659,7 @@ module.exports = grammar({
$.expression,
';',
),
non_empty_mode: $ => choice(
non_empty_mode: $ => choice( // ARM 6.1
reservedWord('in'),
seq(
reservedWord('in'),
@ -1690,7 +1681,7 @@ module.exports = grammar({
),
number_declaration: $ => seq(
$._defining_identifier_list,
';',
':',
reservedWord('constant'),
$._assign_value,
';',
@ -1704,7 +1695,7 @@ module.exports = grammar({
choice(
$._subtype_indication,
$.access_definition,
$._array_type_definition,
$.array_type_definition,
),
optional($._assign_value),
optional($.aspect_specification),
@ -1777,14 +1768,12 @@ module.exports = grammar({
repeat1($._task_item),
)),
reservedWord('end'),
optional($.identifier),
field('endname', optional($.identifier)),
),
overriding_indicator: $ => seq(
optional(reservedWord('not')),
reservedWord('overriding'),
),
_non_empty_parameter_profile: $ => // ??? inline
$.formal_part,
_parameter_and_result_profile: $ => seq(
optional($.formal_part),
$.result_profile,
@ -1792,13 +1781,19 @@ module.exports = grammar({
parameter_specification: $ => seq( // ARM 6.1
$._defining_identifier_list,
':',
choice(
seq(
optional(reservedWord('aliased')),
optional($.non_empty_mode),
optional($.null_exclusion),
field('subtype_mark', $._name),
optional($._assign_value),
),
parameter_specification_list: $ => list_of(
$.access_definition,
),
optional($._assign_value),
optional($.aspect_specification),
),
_parameter_specification_list: $ => list_of(
';',
$.parameter_specification,
),
@ -1842,7 +1837,7 @@ module.exports = grammar({
procedure_specification: $ => seq(
reservedWord('procedure'),
field('name', $._name),
optional($._non_empty_parameter_profile),
optional($.formal_part),
),
record_representation_clause: $ => prec.left(seq( // ARM 13.5.1
reservedWord('for'),

View File

@ -102,56 +102,61 @@
(numeric_literal) @number
;; Highlight the name of subprograms
(procedure_specification
name: (identifier) @function
)
(function_specification
name: (identifier) @function
)
(package_specification
name: (identifier) @function ;; Should use @module
)
(package_body
name: (identifier) @function ;; Should use @module
)
(generic_instantiation
name: (identifier) @function
)
(procedure_specification name: (_) @function)
(function_specification name: (_) @function)
(package_specification name: (_) @function)
(package_body name: (_) @function)
(generic_instantiation name: (_) @function)
;; Some keywords should take different categories depending on the context
;; ??? Doesn't quite work because treesitter choses the longest name for the
;; final highlight
(use_clause "use" @include "type" @include)
(with_clause "private" @include)
(with_clause "limited" @include)
(use_clause (identifier) @namespace)
(with_clause (identifier) @namespace)
(loop_statement "end" @keyword.repeat)
(if_statement "end" @conditional)
(loop_parameter_specification "in" @keyword.repeat)
(loop_parameter_specification "in" @keyword.repeat)
(iterator_specification ["in" "of"] @keyword.repeat)
(range_attribute_designator "range" @keyword.repeat)
(raise_statement "with" @exception)
(subprogram_declaration "is" @keyword.function "abstract" @keyword.function)
(aspect_specification "with" @keyword.function)
;; Change keyword categories inside type definitions.
;; WIP: waiting for simplified tree.
; [
; "is"
; "abstract"
; "access"
; "array"
; "tagged"
; "constant"
; "range"
; "mod"
; "digits"
; "delta"
; "limited"
; "synchronized"
; ]* @keyword.type
(full_type_declaration "is" @type.definition)
(full_type_declaration (_ "access") @type.definition)
(subtype_declaration "is" @type.definition)
(record_definition "end" @type.definition)
(full_type_declaration (_ "access" @type.definition))
(array_type_definition "array" @type.definition "of" @type.definition)
(access_to_object_definition "access" @type.definition)
(access_to_object_definition "access" @type.definition
[
(general_access_modifier "constant" @type.definition)
(general_access_modifier "all" @type.definition)
]
)
(range_constraint "range" @type.definition)
(signed_integer_type_definition "range" @type.definition)
(index_subtype_definition "range" @type.definition)
;; Gray the body of expression functions
(expression_function_declaration
(function_specification)
"is"
(_) @function.expression
)
(subprogram_declaration (aspect_specification) @function.expression)
;; Highlight full subprogram specifications
(subprogram_body
[
(procedure_specification)
(function_specification)
] @function.spec
)
;(subprogram_body
; [
; (procedure_specification)
; (function_specification)
; ] @function.spec
;)
;; Highlight errors in red. This is not very useful in practice, as text will
;; be highlighted as user types, and the error could be elsewhere in the code.

View File

@ -7,15 +7,25 @@
(function_specification) @scope
(block_statement) @scope
(procedure_specification name: (_) @definition.var)
(function_specification name: (_) @definition.var)
(with_clause (identifier) @definition.import)
(procedure_specification name: (_) @definition.function)
(function_specification name: (_) @definition.function)
(package_specification name: (_) @definition.var)
(package_body name: (_) @definition.var)
(generic_instantiation . name: (_) @definition.var)
(component_declaration (identifier) @definition.var)
(exception_declaration (identifier) @definition.var)
(formal_object_declaration (identifier) @definition.var)
(object_declaration (identifier) @definition.var)
(parameter_specification (identifier) @definition.var)
(component_declaration . (identifier) @definition.var)
(exception_declaration . (identifier) @definition.var)
(formal_object_declaration . (identifier) @definition.var)
(object_declaration . (identifier) @definition.var)
(parameter_specification . (identifier) @definition.var)
(full_type_declaration . (identifier) @definition.type)
(private_type_declaration . (identifier) @definition.type)
(private_extension_declaration . (identifier) @definition.type)
(incomplete_type_declaration . (identifier) @definition.type)
(protected_type_declaration . (identifier) @definition.type)
(formal_complete_type_declaration . (identifier) @definition.type)
(formal_incomplete_type_declaration . (identifier) @definition.type)
(task_type_declaration . (identifier) @definition.type)
(subtype_declaration . (identifier) @definition.type)
(identifier) @reference

View File

@ -2917,7 +2917,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_non_empty_parameter_profile"
"name": "formal_part"
},
{
"type": "BLANK"
@ -4668,7 +4668,7 @@
},
{
"type": "SYMBOL",
"name": "_array_type_definition"
"name": "array_type_definition"
},
{
"type": "SYMBOL",
@ -4688,99 +4688,42 @@
}
]
},
"_array_type_definition": {
"array_type_definition": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "PATTERN",
"value": "[aA][rR][rR][aA][yY]"
}
}
},
"named": false,
"value": "array"
},
{
"type": "STRING",
"value": "("
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "unconstrained_array_definition"
},
{
"type": "SYMBOL",
"name": "constrained_array_definition"
}
]
},
"unconstrained_array_definition": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "PATTERN",
"value": "[aA][rR][rR][aA][yY]"
}
}
},
"named": false,
"value": "array"
},
{
"type": "STRING",
"value": "("
"name": "_discrete_subtype_definition_list"
},
{
"type": "SYMBOL",
"name": "_index_subtype_definition_list"
},
{
"type": "STRING",
"value": ")"
},
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "PATTERN",
"value": "[oO][fF]"
}
}
},
"named": false,
"value": "of"
},
{
"type": "SYMBOL",
"name": "component_definition"
}
]
},
"constrained_array_definition": {
"type": "SEQ",
"members": [
{
"type": "ALIAS",
"content": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": 2,
"content": {
"type": "PATTERN",
"value": "[aA][rR][rR][aA][yY]"
}
}
},
"named": false,
"value": "array"
},
{
"type": "STRING",
"value": "("
},
{
"type": "SYMBOL",
"name": "_discrete_subtype_definition_list"
},
{
"type": "STRING",
"value": ")"
@ -8204,7 +8147,7 @@
},
{
"type": "SYMBOL",
"name": "parameter_specification_list"
"name": "_parameter_specification_list"
},
{
"type": "STRING",
@ -9440,7 +9383,7 @@
},
"formal_array_type_definition": {
"type": "SYMBOL",
"name": "_array_type_definition"
"name": "array_type_definition"
},
"formal_access_type_definition": {
"type": "SYMBOL",
@ -10230,7 +10173,7 @@
},
{
"type": "STRING",
"value": ";"
"value": ":"
},
{
"type": "ALIAS",
@ -10337,7 +10280,7 @@
},
{
"type": "SYMBOL",
"name": "_array_type_definition"
"name": "array_type_definition"
}
]
},
@ -10769,6 +10712,9 @@
"value": "end"
},
{
"type": "FIELD",
"name": "endname",
"content": {
"type": "CHOICE",
"members": [
{
@ -10780,6 +10726,7 @@
}
]
}
}
]
},
"overriding_indicator": {
@ -10827,10 +10774,6 @@
}
]
},
"_non_empty_parameter_profile": {
"type": "SYMBOL",
"name": "formal_part"
},
"_parameter_and_result_profile": {
"type": "SEQ",
"members": [
@ -10863,6 +10806,12 @@
"type": "STRING",
"value": ":"
},
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
@ -10918,6 +10867,14 @@
"type": "SYMBOL",
"name": "_name"
}
}
]
},
{
"type": "SYMBOL",
"name": "access_definition"
}
]
},
{
"type": "CHOICE",
@ -10930,10 +10887,22 @@
"type": "BLANK"
}
]
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "aspect_specification"
},
{
"type": "BLANK"
}
]
}
]
},
"parameter_specification_list": {
"_parameter_specification_list": {
"type": "SEQ",
"members": [
{
@ -11242,7 +11211,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_non_empty_parameter_profile"
"name": "formal_part"
},
{
"type": "BLANK"

View File

@ -405,6 +405,100 @@
]
}
},
{
"type": "array_type_definition",
"named": true,
"fields": {
"subtype_mark": {
"multiple": true,
"required": false,
"types": [
{
"type": ".",
"named": false
},
{
"type": "attribute_designator",
"named": true
},
{
"type": "character_literal",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "qualified_expression",
"named": true
},
{
"type": "reduction_attribute_designator",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "target_name",
"named": true
},
{
"type": "tick",
"named": true
},
{
"type": "value_sequence",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "component_definition",
"named": true
},
{
"type": "delta_constraint",
"named": true
},
{
"type": "digits_constraint",
"named": true
},
{
"type": "index_constraint",
"named": true
},
{
"type": "index_subtype_definition",
"named": true
},
{
"type": "null_exclusion",
"named": true
},
{
"type": "range_constraint",
"named": true
},
{
"type": "range_g",
"named": true
}
]
}
},
{
"type": "aspect_association",
"named": true,
@ -1372,96 +1466,6 @@
]
}
},
{
"type": "constrained_array_definition",
"named": true,
"fields": {
"subtype_mark": {
"multiple": true,
"required": false,
"types": [
{
"type": ".",
"named": false
},
{
"type": "attribute_designator",
"named": true
},
{
"type": "character_literal",
"named": true
},
{
"type": "function_call",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "qualified_expression",
"named": true
},
{
"type": "reduction_attribute_designator",
"named": true
},
{
"type": "string_literal",
"named": true
},
{
"type": "target_name",
"named": true
},
{
"type": "tick",
"named": true
},
{
"type": "value_sequence",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "component_definition",
"named": true
},
{
"type": "delta_constraint",
"named": true
},
{
"type": "digits_constraint",
"named": true
},
{
"type": "index_constraint",
"named": true
},
{
"type": "null_exclusion",
"named": true
},
{
"type": "range_constraint",
"named": true
},
{
"type": "range_g",
"named": true
}
]
}
},
{
"type": "decimal_fixed_point_definition",
"named": true,
@ -3480,11 +3484,7 @@
"required": true,
"types": [
{
"type": "constrained_array_definition",
"named": true
},
{
"type": "unconstrained_array_definition",
"type": "array_type_definition",
"named": true
}
]
@ -4035,11 +4035,11 @@
"named": true,
"fields": {},
"children": {
"multiple": false,
"multiple": true,
"required": true,
"types": [
{
"type": "parameter_specification_list",
"type": "parameter_specification",
"named": true
}
]
@ -4091,11 +4091,11 @@
"named": true
},
{
"type": "aspect_specification",
"type": "array_type_definition",
"named": true
},
{
"type": "constrained_array_definition",
"type": "aspect_specification",
"named": true
},
{
@ -4153,10 +4153,6 @@
{
"type": "task_type_declaration",
"named": true
},
{
"type": "unconstrained_array_definition",
"named": true
}
]
}
@ -5996,11 +5992,11 @@
"named": true
},
{
"type": "aspect_specification",
"type": "array_type_definition",
"named": true
},
{
"type": "constrained_array_definition",
"type": "aspect_specification",
"named": true
},
{
@ -6034,10 +6030,6 @@
{
"type": "single_task_declaration",
"named": true
},
{
"type": "unconstrained_array_definition",
"named": true
}
]
}
@ -6698,7 +6690,7 @@
"fields": {
"subtype_mark": {
"multiple": true,
"required": true,
"required": false,
"types": [
{
"type": ".",
@ -6751,6 +6743,14 @@
"multiple": true,
"required": true,
"types": [
{
"type": "access_definition",
"named": true
},
{
"type": "aspect_specification",
"named": true
},
{
"type": "expression",
"named": true
@ -6770,21 +6770,6 @@
]
}
},
{
"type": "parameter_specification_list",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "parameter_specification",
"named": true
}
]
}
},
{
"type": "positional_array_aggregate",
"named": true,
@ -9056,7 +9041,18 @@
{
"type": "task_definition",
"named": true,
"fields": {},
"fields": {
"endname": {
"multiple": false,
"required": false,
"types": [
{
"type": "identifier",
"named": true
}
]
}
},
"children": {
"multiple": true,
"required": true,
@ -9077,10 +9073,6 @@
"type": "enumeration_representation_clause",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "record_representation_clause",
"named": true
@ -9344,25 +9336,6 @@
"named": true,
"fields": {}
},
{
"type": "unconstrained_array_definition",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "component_definition",
"named": true
},
{
"type": "index_subtype_definition",
"named": true
}
]
}
},
{
"type": "unknown_discriminant_part",
"named": true,

58025
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@ -16,7 +16,7 @@ end P;
(identifier)
(full_type_declaration
(identifier)
(constrained_array_definition
(array_type_definition
(range_g
(term
(numeric_literal))
@ -88,7 +88,7 @@ end;
(identifier)
(full_type_declaration
(identifier)
(constrained_array_definition
(array_type_definition
(range_g
(term
(numeric_literal))
@ -129,7 +129,7 @@ end P;
(identifier)
(full_type_declaration
(identifier)
(unconstrained_array_definition
(array_type_definition
(index_subtype_definition
(identifier))
(component_definition
@ -170,7 +170,7 @@ end P;
(identifier)
(full_type_declaration
(identifier)
(unconstrained_array_definition
(array_type_definition
(index_subtype_definition
(identifier))
(index_subtype_definition

View File

@ -51,10 +51,9 @@ end;
(identifier)
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(component_declaration
(identifier)
(component_definition
@ -101,10 +100,9 @@ end;
(identifier)
(identifier))
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(entry_barrier
(expression
(term

View File

@ -39,10 +39,9 @@ end P;
(procedure_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(identifier))
(generic_renaming_declaration
(identifier)

View File

@ -1,3 +1,19 @@
================================================================================
Untyped Constant
================================================================================
A : constant := 111;
--------------------------------------------------------------------------------
(compilation
(compilation_unit
(number_declaration
(identifier)
(expression
(term
(numeric_literal))))))
================================================================================
Factors
================================================================================
@ -202,10 +218,9 @@ end P;
(procedure_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(handled_sequence_of_statements
(statement
(procedure_call_statement

View File

@ -48,14 +48,13 @@ end;
(procedure_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)
(identifier))
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(aspect_specification
(aspect_mark_list
(aspect_association
@ -107,11 +106,10 @@ end;
(function_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)
(identifier))))
(identifier)))
(result_profile
(access_definition
(null_exclusion)
@ -149,10 +147,9 @@ end;
(procedure_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(non_empty_declarative_part
(object_declaration
(identifier)
@ -177,10 +174,9 @@ function F2 (A : Integer) return Boolean
(function_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier))))
(identifier)))
(result_profile
(identifier)))
(expression
@ -206,10 +202,9 @@ function F2 (A : Integer) return Boolean
(function_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier))))
(identifier)))
(result_profile
(identifier)))
(declare_expression
@ -280,10 +275,9 @@ function F (A : Integer) return Boolean
(function_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier))))
(identifier)))
(result_profile
(identifier)))
(if_expression
@ -320,10 +314,9 @@ function F5 (A : Integer) return Boolean
(function_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier))))
(identifier)))
(result_profile
(identifier)))
(expression
@ -359,10 +352,9 @@ function F (A : Integer) return Boolean
(function_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier))))
(identifier)))
(result_profile
(identifier)))
(case_expression
@ -440,10 +432,9 @@ function F (A : My_Array) return Boolean
(function_specification
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier))))
(identifier)))
(result_profile
(identifier)))
(quantified_expression
@ -476,11 +467,10 @@ end "<";
(function_specification
(string_literal)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)
(identifier))))
(identifier)))
(result_profile
(identifier)))
(handled_sequence_of_statements
@ -490,3 +480,22 @@ end "<";
(term
(identifier))))))
(string_literal))))
================================================================================
Access Parameters
================================================================================
procedure Proc (A : access Integer);
--------------------------------------------------------------------------------
(compilation
(compilation_unit
(subprogram_declaration
(procedure_specification
(identifier)
(formal_part
(parameter_specification
(identifier)
(access_definition
(identifier))))))))

View File

@ -44,10 +44,9 @@ end P;
(entry_declaration
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(entry_declaration
(identifier))
(identifier))))
@ -62,10 +61,9 @@ end P;
(accept_statement
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier))))
(identifier)))
(handled_sequence_of_statements
(statement
(null_statement)))
@ -131,10 +129,9 @@ end;
(entry_declaration
(identifier)
(formal_part
(parameter_specification_list
(parameter_specification
(identifier)
(identifier)))))
(identifier))))
(identifier))))
(full_type_declaration
(task_type_declaration