Add discriminant_constraint

This commit is contained in:
Emmanuel Briot 2022-12-14 11:55:25 +01:00
parent a63a4f53d3
commit b9645c74b2
6 changed files with 32062 additions and 31341 deletions

View File

@ -110,6 +110,7 @@ module.exports = grammar({
], ],
inline: $ => [ inline: $ => [
$._name_not_function_call, $._name_not_function_call,
$._name_for_component_choice,
], ],
rules: { rules: {
@ -150,6 +151,12 @@ module.exports = grammar({
$._name_not_function_call, $._name_not_function_call,
$.function_call, $.function_call,
), ),
_name_for_component_choice: $ => choice(
// Do not allow slice, function_call,... as opposed to what RM allows
$.identifier,
$.string_literal,
),
selected_component: $ => prec.left(seq( // RM 4.1.3 selected_component: $ => prec.left(seq( // RM 4.1.3
field('prefix', $._name), field('prefix', $._name),
seq( seq(
@ -392,9 +399,22 @@ module.exports = grammar({
field('subtype_mark', $._name_not_function_call), field('subtype_mark', $._name_not_function_call),
optional($._constraint), optional($._constraint),
), ),
_constraint: $ => choice( discriminant_constraint: $ => seq( // RM 3.7.1
'(',
comma_separated_list_of($.discriminant_association),
')',
),
discriminant_association: $ => seq( // RM 3.7.1
optional(seq(
list_of('|', $._name_for_component_choice),
'=>',
)),
$.expression,
),
_constraint: $ => choice( // RM 3.2.2
$._scalar_constraint, $._scalar_constraint,
$.index_constraint, $.index_constraint,
$.discriminant_constraint,
), ),
_scalar_constraint: $ => choice( _scalar_constraint: $ => choice(
$.range_constraint, $.range_constraint,
@ -670,11 +690,7 @@ module.exports = grammar({
), ),
component_choice_list: $ => choice( // RM 4.3.1 component_choice_list: $ => choice( // RM 4.3.1
reservedWord('others'), reservedWord('others'),
list_of('|', choice( // Do not allow slice, function_call,... list_of('|', $._name_for_component_choice),
$.identifier, // as opposed to what the ARM allows
$.selected_component,
$.string_literal,
)),
), ),
_aggregate: $ => choice( // RM 4.3 _aggregate: $ => choice( // RM 4.3
$.record_aggregate, $.record_aggregate,
@ -766,7 +782,7 @@ module.exports = grammar({
reservedWord('not'), reservedWord('not'),
reservedWord('null'), reservedWord('null'),
), ),
index_constraint: $ => seq( index_constraint: $ => seq( // RM 3.6.1
'(', '(',
comma_separated_list_of($._discrete_range), comma_separated_list_of($._discrete_range),
')', ')',

View File

@ -193,6 +193,19 @@
} }
] ]
}, },
"_name_for_component_choice": {
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "identifier"
},
{
"type": "SYMBOL",
"name": "string_literal"
}
]
},
"selected_component": { "selected_component": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 0, "value": 0,
@ -1770,6 +1783,95 @@
} }
] ]
}, },
"discriminant_constraint": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "("
},
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "discriminant_association"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": ","
},
{
"type": "SYMBOL",
"name": "discriminant_association"
}
]
}
}
]
},
{
"type": "STRING",
"value": ")"
}
]
},
"discriminant_association": {
"type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_name_for_component_choice"
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "|"
},
{
"type": "SYMBOL",
"name": "_name_for_component_choice"
}
]
}
}
]
},
{
"type": "STRING",
"value": "=>"
}
]
},
{
"type": "BLANK"
}
]
},
{
"type": "SYMBOL",
"name": "expression"
}
]
},
"_constraint": { "_constraint": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -1780,6 +1882,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "index_constraint" "name": "index_constraint"
},
{
"type": "SYMBOL",
"name": "discriminant_constraint"
} }
] ]
}, },
@ -3417,23 +3523,10 @@
}, },
{ {
"type": "SEQ", "type": "SEQ",
"members": [
{
"type": "CHOICE",
"members": [ "members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_name_for_component_choice"
},
{
"type": "SYMBOL",
"name": "selected_component"
},
{
"type": "SYMBOL",
"name": "string_literal"
}
]
}, },
{ {
"type": "REPEAT", "type": "REPEAT",
@ -3444,22 +3537,9 @@
"type": "STRING", "type": "STRING",
"value": "|" "value": "|"
}, },
{
"type": "CHOICE",
"members": [
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "identifier" "name": "_name_for_component_choice"
},
{
"type": "SYMBOL",
"name": "selected_component"
},
{
"type": "SYMBOL",
"name": "string_literal"
}
]
} }
] ]
} }
@ -14817,7 +14897,8 @@
"precedences": [], "precedences": [],
"externals": [], "externals": [],
"inline": [ "inline": [
"_name_not_function_call" "_name_not_function_call",
"_name_for_component_choice"
], ],
"supertypes": [] "supertypes": []
} }

View File

@ -366,6 +366,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "general_access_modifier", "type": "general_access_modifier",
"named": true "named": true
@ -623,6 +627,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "index_constraint", "type": "index_constraint",
"named": true "named": true
@ -1312,6 +1320,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -1605,10 +1617,6 @@
"type": "identifier", "type": "identifier",
"named": true "named": true
}, },
{
"type": "selected_component",
"named": true
},
{ {
"type": "string_literal", "type": "string_literal",
"named": true "named": true
@ -1824,6 +1832,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "index_constraint", "type": "index_constraint",
"named": true "named": true
@ -2262,6 +2274,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "function_call", "type": "function_call",
"named": true "named": true
@ -2419,6 +2435,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -2457,6 +2477,44 @@
] ]
} }
}, },
{
"type": "discriminant_association",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "expression",
"named": true
},
{
"type": "identifier",
"named": true
},
{
"type": "string_literal",
"named": true
}
]
}
},
{
"type": "discriminant_constraint",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "discriminant_association",
"named": true
}
]
}
},
{ {
"type": "discriminant_specification", "type": "discriminant_specification",
"named": true, "named": true,
@ -2933,6 +2991,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -3031,6 +3093,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -3696,6 +3762,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -6323,6 +6393,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "index_constraint", "type": "index_constraint",
"named": true "named": true
@ -6659,6 +6733,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -6800,6 +6878,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true
@ -7346,6 +7428,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "expression", "type": "expression",
"named": true "named": true
@ -8302,6 +8388,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "function_call", "type": "function_call",
"named": true "named": true
@ -10526,6 +10616,10 @@
"type": "digits_constraint", "type": "digits_constraint",
"named": true "named": true
}, },
{
"type": "discriminant_constraint",
"named": true
},
{ {
"type": "identifier", "type": "identifier",
"named": true "named": true

63068
src/parser.c

File diff suppressed because it is too large Load Diff

View File

@ -507,3 +507,42 @@ end;
(primary_null)))))))) (primary_null))))))))
(handled_sequence_of_statements (handled_sequence_of_statements
(null_statement))))) (null_statement)))))
========================
Record with discr
========================
procedure Proc is
type Rec (Len : Natural) is null record;
R : Rec (0);
begin
null;
end;
--------
(compilation
(compilation_unit
(subprogram_body
(procedure_specification
(identifier))
(non_empty_declarative_part
(full_type_declaration
(identifier)
(known_discriminant_part
(discriminant_specification_list
(discriminant_specification
(identifier)
(identifier))))
(record_type_definition
(record_definition)))
(object_declaration
(identifier)
(identifier)
(discriminant_constraint
(discriminant_association
(expression
(term
(numeric_literal)))))))
(handled_sequence_of_statements
(null_statement)))))

View File

@ -580,3 +580,24 @@ package P is new Pack ("+" => "+", "-" => Imported."+");
(selected_component (selected_component
(identifier) (identifier)
(string_literal)))))))))) (string_literal))))))))))
================================================================================
Function renaming
================================================================================
function F (S : String) return Boolean renames F2;
--------------------------------------------------------------------------------
(compilation
(compilation_unit
(subprogram_renaming_declaration
(function_specification
(identifier)
(formal_part
(parameter_specification
(identifier)
(identifier)))
(result_profile
(identifier)))
(identifier))))