Some more cases of expression functions
This commit is contained in:
parent
8e44c8bc3b
commit
c0b04e4be1
|
|
@ -128,10 +128,7 @@ end P;
|
|||
(identifier))))))))))
|
||||
(array_component_association
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(subtype_indication
|
||||
(name
|
||||
(identifier)))))
|
||||
(discrete_choice))
|
||||
(assoc_expression
|
||||
(expression
|
||||
(relation
|
||||
|
|
|
|||
|
|
@ -310,10 +310,7 @@ end;
|
|||
(identifier))))))))
|
||||
(variant
|
||||
(discrete_choice_list
|
||||
(discrete_choice
|
||||
(subtype_indication
|
||||
(name
|
||||
(identifier)))))
|
||||
(discrete_choice))
|
||||
(component_list)))))))))))))
|
||||
|
||||
================================================================================
|
||||
|
|
|
|||
|
|
@ -41,8 +41,6 @@ procedures
|
|||
package P is
|
||||
procedure A (P1, P2 : Integer; P3 : Float)
|
||||
with Inline;
|
||||
procedure B is abstract;
|
||||
procedure C is abstract with Inline;
|
||||
end;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
|
@ -75,13 +73,31 @@ end;
|
|||
(aspect_mark_list
|
||||
(aspect_association
|
||||
(aspect_mark
|
||||
(identifier))))))
|
||||
(abstract_subprogram_declaration
|
||||
(identifier)))))))))
|
||||
|
||||
================================================================================
|
||||
abstract procedures
|
||||
================================================================================
|
||||
|
||||
package P is
|
||||
procedure B is abstract;
|
||||
overriding procedure C is abstract with Inline;
|
||||
end;
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(package_specification
|
||||
(name
|
||||
(identifier))
|
||||
(subprogram_declaration
|
||||
(subprogram_specification
|
||||
(procedure_specification
|
||||
(name
|
||||
(identifier)))))
|
||||
(abstract_subprogram_declaration
|
||||
(subprogram_declaration
|
||||
(overriding_indicator)
|
||||
(subprogram_specification
|
||||
(procedure_specification
|
||||
(name
|
||||
|
|
@ -92,6 +108,7 @@ end;
|
|||
(aspect_mark
|
||||
(identifier)))))))))
|
||||
|
||||
|
||||
================================================================================
|
||||
functions
|
||||
================================================================================
|
||||
|
|
@ -198,7 +215,7 @@ end;
|
|||
(identifier))))))))))
|
||||
|
||||
================================================================================
|
||||
expression function membership
|
||||
Expression function membership
|
||||
================================================================================
|
||||
|
||||
function F2 (A : Integer) return Boolean
|
||||
|
|
@ -446,3 +463,143 @@ function F5 (A : Integer) return Boolean
|
|||
(primary
|
||||
(name
|
||||
(identifier))))))))))))))))))))))))
|
||||
|
||||
======
|
||||
Expression function case
|
||||
======
|
||||
|
||||
function F (A : Integer) return Boolean
|
||||
is (case A + 1 is
|
||||
when 0 .. 1 | 3 .. 4 => True,
|
||||
when others => False);
|
||||
|
||||
------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(expression_function_declaration
|
||||
(function_specification
|
||||
(name
|
||||
(identifier))
|
||||
(parameter_and_result_profile
|
||||
(formal_part
|
||||
(parameter_specification_list
|
||||
(parameter_specification
|
||||
(defining_identifier_list
|
||||
(identifier))
|
||||
(name
|
||||
(identifier)))))
|
||||
(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))))))))
|
||||
(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 quantified
|
||||
=====
|
||||
|
||||
function F (A : My_Array) return Boolean
|
||||
is (for some E of A => E = 1);
|
||||
|
||||
|
||||
------
|
||||
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(expression_function_declaration
|
||||
(function_specification
|
||||
(name
|
||||
(identifier))
|
||||
(parameter_and_result_profile
|
||||
(formal_part
|
||||
(parameter_specification_list
|
||||
(parameter_specification
|
||||
(defining_identifier_list
|
||||
(identifier))
|
||||
(name
|
||||
(identifier)))))
|
||||
(result_profile
|
||||
(name
|
||||
(identifier)))))
|
||||
(aggregate
|
||||
(quantified_expression
|
||||
(quantifier)
|
||||
(iterator_specification
|
||||
(identifier)
|
||||
(name
|
||||
(identifier)))
|
||||
(assoc_expression
|
||||
(expression
|
||||
(relation
|
||||
(simple_expression
|
||||
(term
|
||||
(factor
|
||||
(primary
|
||||
(name
|
||||
(identifier))))))
|
||||
(relational_operator)
|
||||
(simple_expression
|
||||
(term
|
||||
(factor
|
||||
(primary
|
||||
(numeric_literal)))))))))))))
|
||||
|
|
|
|||
90
grammar.js
90
grammar.js
|
|
@ -42,13 +42,9 @@ module.exports = grammar({
|
|||
word: $ => $.identifier,
|
||||
|
||||
conflicts: $ => [
|
||||
// "function_specification is" could be either an expression function
|
||||
// specification, or a function specification
|
||||
// ??? Maybe we can merge both in the grammar
|
||||
[$.expression_function_declaration, $.subprogram_specification],
|
||||
|
||||
// ??? Maybe we can merge these
|
||||
[$.null_procedure_declaration, $.subprogram_specification],
|
||||
[$.expression_function_declaration, $.subprogram_specification],
|
||||
|
||||
// "'for' _direct_name * 'use'" could also be "'for' name * 'use'" as
|
||||
// specified in at_clause.
|
||||
|
|
@ -280,9 +276,8 @@ module.exports = grammar({
|
|||
$.object_declaration,
|
||||
$.number_declaration,
|
||||
$.subprogram_declaration,
|
||||
$.abstract_subprogram_declaration,
|
||||
$.null_procedure_declaration,
|
||||
$.expression_function_declaration,
|
||||
$.null_procedure_declaration,
|
||||
$._package_declaration,
|
||||
$.renaming_declaration,
|
||||
$.exception_declaration,
|
||||
|
|
@ -402,12 +397,13 @@ module.exports = grammar({
|
|||
list_of(seq(reservedWord('or'), reservedWord('else')), $.relation),
|
||||
list_of(reservedWord('xor'), $.relation),
|
||||
),
|
||||
assoc_expression: $ => seq(
|
||||
assoc_expression: $ => choice(
|
||||
seq('=>', '<>'),
|
||||
$._non_default_assoc_expression,
|
||||
),
|
||||
_non_default_assoc_expression: $ => seq(
|
||||
'=>',
|
||||
choice(
|
||||
$.expression,
|
||||
'<>',
|
||||
),
|
||||
$.expression,
|
||||
),
|
||||
relation: $ => choice(
|
||||
seq(
|
||||
|
|
@ -519,7 +515,38 @@ module.exports = grammar({
|
|||
),
|
||||
conditional_expression: $ => choice(
|
||||
$.if_expression,
|
||||
// $.case_expression,
|
||||
$.case_expression,
|
||||
),
|
||||
conditional_quantified_expression: $ => choice(
|
||||
$.if_expression,
|
||||
$.case_expression,
|
||||
$.quantified_expression,
|
||||
),
|
||||
quantified_expression: $ => seq(
|
||||
reservedWord('for'),
|
||||
$.quantifier,
|
||||
choice(
|
||||
$.loop_parameter_specification,
|
||||
$.iterator_specification,
|
||||
),
|
||||
$.assoc_expression,
|
||||
),
|
||||
quantifier: $ => choice(
|
||||
reservedWord('all'),
|
||||
reservedWord('some'),
|
||||
),
|
||||
case_expression: $ => seq(
|
||||
reservedWord('case'),
|
||||
$.expression,
|
||||
reservedWord('is'),
|
||||
comma_separated_list_of($.case_expression_alternative),
|
||||
),
|
||||
case_expression_alternative: $ => seq(
|
||||
reservedWord('when'),
|
||||
$.discrete_choice_list,
|
||||
$._non_default_assoc_expression,
|
||||
// '=>',
|
||||
// $.expression,
|
||||
),
|
||||
component_choice_list: $ =>
|
||||
list_of('|', $.selector_name),
|
||||
|
|
@ -532,7 +559,7 @@ module.exports = grammar({
|
|||
'(',
|
||||
choice(
|
||||
$.conditional_expression,
|
||||
// $.quantified_expression,
|
||||
$.quantified_expression,
|
||||
// $.declare_expression,
|
||||
),
|
||||
')',
|
||||
|
|
@ -796,14 +823,6 @@ module.exports = grammar({
|
|||
$.access_definition,
|
||||
),
|
||||
),
|
||||
abstract_subprogram_declaration: $ => seq(
|
||||
optional($.overriding_indicator),
|
||||
$.subprogram_specification,
|
||||
reservedWord('is'),
|
||||
reservedWord('abstract'),
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
array_aggregate: $ => choice(
|
||||
$.positional_array_aggregate,
|
||||
$.null_array_aggregate,
|
||||
|
|
@ -861,6 +880,7 @@ module.exports = grammar({
|
|||
$.expression,
|
||||
$.subtype_indication,
|
||||
$.range_g,
|
||||
reservedWord('others'),
|
||||
),
|
||||
aspect_association: $ => seq(
|
||||
$.aspect_mark,
|
||||
|
|
@ -898,7 +918,6 @@ module.exports = grammar({
|
|||
at_clause: $ => seq(
|
||||
reservedWord('for'),
|
||||
$.identifier,
|
||||
// $._direct_name,
|
||||
reservedWord('use'),
|
||||
reservedWord('at'),
|
||||
$.expression,
|
||||
|
|
@ -984,14 +1003,6 @@ module.exports = grammar({
|
|||
$.exception_handler,
|
||||
$.pragma_g,
|
||||
)),
|
||||
expression_function_declaration: $ => seq(
|
||||
optional($.overriding_indicator),
|
||||
$.function_specification,
|
||||
reservedWord('is'),
|
||||
$.aggregate,
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
formal_part: $ => seq(
|
||||
'(',
|
||||
$.parameter_specification_list,
|
||||
|
|
@ -1172,11 +1183,6 @@ module.exports = grammar({
|
|||
)),
|
||||
';'
|
||||
),
|
||||
conditional_quantified_expression: $ => choice(
|
||||
$.if_expression,
|
||||
// $.case_expression,
|
||||
// $.quantified_expression,
|
||||
),
|
||||
if_expression: $ => seq(
|
||||
reservedWord('if'),
|
||||
field('condition', $.expression),
|
||||
|
|
@ -1255,6 +1261,18 @@ module.exports = grammar({
|
|||
subprogram_declaration: $ => seq(
|
||||
optional($.overriding_indicator),
|
||||
$.subprogram_specification,
|
||||
field('is_abstract', optional(seq(
|
||||
reservedWord('is'),
|
||||
reservedWord('abstract'),
|
||||
))),
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
expression_function_declaration: $ => seq(
|
||||
optional($.overriding_indicator),
|
||||
$.function_specification,
|
||||
reservedWord('is'),
|
||||
$.aggregate,
|
||||
optional($.aspect_specification),
|
||||
';',
|
||||
),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"generate": "tree-sitter generate",
|
||||
"test": "tree-sitter generate && tree-sitter test",
|
||||
"test": "tree-sitter generate && time tree-sitter test",
|
||||
"update-test": "tree-sitter test --update"
|
||||
},
|
||||
"main": "bindings/node"
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user