diff --git a/corpus/packages.txt b/corpus/packages.txt index 0261530..ff22218 100644 --- a/corpus/packages.txt +++ b/corpus/packages.txt @@ -16,7 +16,8 @@ use Ada.Text_IO, System; (name_list (name (identifier) - (identifier)) + (name + (identifier))) (name (identifier))))) (comment) @@ -41,13 +42,14 @@ use Ada.Text_IO, System; (name_list (name (identifier) - (identifier)) + (name + (identifier))) (name (identifier)))))) -===== +================================================================================ Case insensitive -===== +================================================================================ PACkaGe P1 Is enD; @@ -58,7 +60,7 @@ enD; (compilation_unit (package_specification (name - (identifier))))) + (identifier))))) ================================================================================ multiple compilation units @@ -91,12 +93,13 @@ end; (package_specification (name (identifier) - (identifier)) + (name + (identifier))) (comment)))) -========= +================================================================================ body -========= +================================================================================ package body Child.P2 is package body Nested is @@ -107,14 +110,16 @@ begin null; end Child.P2; ---- +-------------------------------------------------------------------------------- + (compilation (compilation_unit (proper_body (package_body (name (identifier) - (identifier)) + (name + (identifier))) (non_empty_declarative_part (declarative_item_pragma (proper_body @@ -135,7 +140,8 @@ end Child.P2; (null_statement))))) (name (identifier) - (identifier)))))) + (name + (identifier))))))) ================================================================================ separate @@ -147,18 +153,18 @@ end; -------------------------------------------------------------------------------- (compilation - (compilation_unit - (subunit - (name - (identifier)) - (proper_body - (package_body - (name - (identifier))))))) + (compilation_unit + (subunit + (name + (identifier)) + (proper_body + (package_body + (name + (identifier))))))) -========================== +================================================================================ private types -========================= +================================================================================ package P is type A is private; @@ -166,42 +172,42 @@ package P is type C is abstract tagged limited private with Size => 8; end; ------------ +-------------------------------------------------------------------------------- - (compilation - (compilation_unit - (package_specification - (name - (identifier)) - (type_declaration - (private_type_declaration - (identifier))) - (type_declaration - (private_extension_declaration - (identifier) - (subtype_indication - (name - (identifier))))) - (type_declaration - (private_type_declaration - (identifier) - (aspect_specification - (aspect_mark_list - (aspect_association - (aspect_mark - (identifier)) - (aspect_definition - (expression - (relation - (simple_expression - (term - (factor - (primary - (numeric_literal)))))))))))))))) +(compilation + (compilation_unit + (package_specification + (name + (identifier)) + (type_declaration + (private_type_declaration + (identifier))) + (type_declaration + (private_extension_declaration + (identifier) + (subtype_indication + (name + (identifier))))) + (type_declaration + (private_type_declaration + (identifier) + (aspect_specification + (aspect_mark_list + (aspect_association + (aspect_mark + (identifier)) + (aspect_definition + (expression + (relation + (simple_expression + (term + (factor + (primary + (numeric_literal)))))))))))))))) -========== +================================================================================ incomplete types -========== +================================================================================ package P is private @@ -211,33 +217,32 @@ private type T is tagged; end; --------------- - - (compilation - (compilation_unit - (package_specification - (name - (identifier)) - (type_declaration - (incomplete_type_declaration - (identifier))) - (type_declaration - (incomplete_type_declaration - (identifier) - (discriminant_part - (known_discriminant_part - (discriminant_specification_list - (discriminant_specification - (defining_identifier_list - (identifier)) - (name - (identifier)))))))) - (type_declaration - (incomplete_type_declaration - (identifier) - (discriminant_part - (unknown_discriminant_part)))) - (type_declaration - (incomplete_type_declaration - (identifier)))))) +-------------------------------------------------------------------------------- +(compilation + (compilation_unit + (package_specification + (name + (identifier)) + (type_declaration + (incomplete_type_declaration + (identifier))) + (type_declaration + (incomplete_type_declaration + (identifier) + (discriminant_part + (known_discriminant_part + (discriminant_specification_list + (discriminant_specification + (defining_identifier_list + (identifier)) + (name + (identifier)))))))) + (type_declaration + (incomplete_type_declaration + (identifier) + (discriminant_part + (unknown_discriminant_part)))) + (type_declaration + (incomplete_type_declaration + (identifier)))))) diff --git a/corpus/renames.txt b/corpus/renames.txt index b7cc326..cd761e6 100644 --- a/corpus/renames.txt +++ b/corpus/renames.txt @@ -51,7 +51,8 @@ end P; (identifier)) (name (identifier) - (identifier))))) + (name + (identifier)))))) (declarative_item_pragma (renaming_declaration (subprogram_renaming_declaration diff --git a/corpus/statements.txt b/corpus/statements.txt new file mode 100644 index 0000000..d5788db --- /dev/null +++ b/corpus/statements.txt @@ -0,0 +1,263 @@ +================================================================================ +While +================================================================================ + +procedure P is +begin + while True loop + exit; + exit when A > 0; + 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 + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier))))))))) + (sequence_of_statements + (statement + (simple_statement + (exit_statement))) + (statement + (simple_statement + (exit_statement + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier)))))) + (relational_operator) + (simple_expression + (term + (factor + (primary + (numeric_literal)))))))))))))))))))) + +================================================================================ +For loops +================================================================================ + +procedure P is +begin + for E in Pkg.Arr'Range loop + goto end_loop; + + <> + end loop; + + for E of reverse Arr loop + delay 1.0; + end loop; +end P; + +-------------------------------------------------------------------------------- + +(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 + (attribute_reference + (name + (identifier) + (name + (identifier))) + (tick) + (attribute_designator + (identifier)))))) + (sequence_of_statements + (statement + (simple_statement + (goto_statement + (name + (identifier))))) + (label + (identifier)))))) + (statement + (compound_statement + (loop_statement + (iteration_scheme + (iterator_specification + (identifier) + (name + (identifier)))) + (sequence_of_statements + (statement + (simple_statement + (delay_statement + (delay_relative_statement + (expression + (relation + (simple_expression + (term + (factor + (primary + (numeric_literal))))))))))))))))) + (name + (identifier)))))) + +================================================================================ +Named loop +================================================================================ + +procedure P is +begin + Main: + loop + exit Main; + end loop Main; +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 + (loop_label + (identifier)) + (sequence_of_statements + (statement + (simple_statement + (exit_statement + (name + (identifier)))))) + (identifier)))))))))) + +================================================================================ +Return +================================================================================ + +function F return Boolean is +begin + return True; +end F; + +-------------------------------------------------------------------------------- + +(compilation + (compilation_unit + (proper_body + (subprogram_body + (subprogram_specification + (function_specification + (name + (identifier)) + (parameter_and_result_profile + (result_profile + (name + (identifier)))))) + (handled_sequence_of_statements + (sequence_of_statements + (statement + (simple_statement + (simple_return_statement + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier))))))))))))) + (name + (identifier)))))) + +================================================================================ +Procedure call +================================================================================ + +procedure P (A : Integer) is +begin + P2 (1, False); +end P; + +-------------------------------------------------------------------------------- + +(compilation + (compilation_unit + (proper_body + (subprogram_body + (subprogram_specification + (procedure_specification + (name + (identifier)) + (non_empty_parameter_profile + (formal_part + (parameter_specification_list + (parameter_specification + (defining_identifier_list + (identifier)) + (name + (identifier)))))))) + (handled_sequence_of_statements + (sequence_of_statements + (statement + (simple_statement + (procedure_call_statement + (name + (identifier)) + (actual_parameter_part + (parameter_association + (expression + (relation + (simple_expression + (term + (factor + (primary + (numeric_literal)))))))) + (parameter_association + (expression + (relation + (simple_expression + (term + (factor + (primary + (name + (identifier))))))))))))))) + (name + (identifier)))))) diff --git a/grammar.js b/grammar.js index 1288676..79d71e3 100644 --- a/grammar.js +++ b/grammar.js @@ -66,9 +66,17 @@ module.exports = grammar({ [$.attribute_definition_clause, $.attribute_reference], + // _direct_name '.' name . ''' + // Could be either _direct_name '.' (attribute_reference name . tick + // or (name _direct_name '.' name) . ''' + [$.name, $.attribute_reference], + // identifier . ':' ... [$.defining_identifier_list, $.object_renaming_declaration, $.exception_renaming_declaration], + [$.defining_identifier_list, $.object_renaming_declaration, + $.exception_renaming_declaration, $._direct_name], + [$.defining_identifier_list, $._direct_name], // 'generic' . 'package' ... [$.generic_formal_part, $.generic_renaming_declaration], @@ -143,13 +151,21 @@ module.exports = grammar({ // ), _direct_name: $ => $.identifier, - name: $ => seq( - $._direct_name, - repeat(seq( - '.', - $.identifier, - )), + name: $ => choice( + seq( + $._direct_name, + optional(seq( + '.', + $.name, + )), +// repeat(seq( +// '.', +// $.identifier, +// )), + ), + $.attribute_reference, ), + name_list: $ => comma_separated_list_of($.name), defining_identifier_list: $ => comma_separated_list_of($.identifier), @@ -244,7 +260,7 @@ module.exports = grammar({ ), iterator_filter: $ => seq( reservedWord('when'), - $.condition, + field('condition', $.expression), ), iterator_specification: $ => seq( $.identifier, @@ -261,7 +277,7 @@ module.exports = grammar({ optional($.iterator_filter), ), attribute_designator: $ => choice( - $.identifier, + $.identifier, // missing function_call reservedWord('access'), reservedWord('delta'), reservedWord('digits'), @@ -409,10 +425,6 @@ module.exports = grammar({ reservedWord('range'), $.range_g, ), - condition: $ => seq( - $.expression, - ';', - ), expression_list: $ => prec.left( comma_separated_list_of($.expression), ), @@ -1249,6 +1261,10 @@ module.exports = grammar({ $.exception_handler_list, )), ), + loop_label: $ => seq( // matches label_opt in ada-mode grammar + field('statement_identifier', $._direct_name), + ':', + ), label: $ => seq( '<<', field('statement_identifier', $._direct_name), @@ -1476,12 +1492,12 @@ module.exports = grammar({ simple_statement: $ => choice( $.null_statement, $.assignment_statement, -// $.exit_statement, -// $.goto_statement, -// $.procedure_call_statement, -// $.simple_return_statement, + $.exit_statement, + $.goto_statement, + $.procedure_call_statement, + $.simple_return_statement, // $.requeue_statement, -// $.delay_statement, + $.delay_statement, // $.abort_statement, // $.raise_statement, $.pragma_g, @@ -1490,9 +1506,99 @@ module.exports = grammar({ repeat($.label), choice( $.simple_statement, -// $.compound_statement, + $.compound_statement, ), ), + compound_statement: $ => choice( +// $.if_statement, +// $.case_statement, + $.loop_statement, +// $.block_statement, +// $.extended_return_statement, +// $.parallel_block_statement, +// $.accept_statement, +// $.select_statement, + ), + exit_statement: $ => seq( + reservedWord('exit'), + optional($.name), + optional(seq( + reservedWord('when'), + field('condition', $.expression), + )), + ';', + ), + goto_statement: $ => seq( + reservedWord('goto'), + $.name, + ';', + ), + delay_statement: $ => choice( + $.delay_until_statement, + $.delay_relative_statement, + ), + delay_until_statement: $ => seq( + reservedWord('delay'), + reservedWord('until'), + $.expression, + ';', + ), + delay_relative_statement: $ => seq( + reservedWord('delay'), + $.expression, + ';', + ), + simple_return_statement: $ => seq( + reservedWord('return'), + optional($.expression), + ';', + ), + procedure_call_statement: $ => seq( + $.name, + optional($.actual_parameter_part), + ';', + ), + loop_statement: $ => seq( + optional($.loop_label), + optional($.iteration_scheme), + reservedWord('loop'), + $.sequence_of_statements, + reservedWord('end'), + reservedWord('loop'), + optional($.identifier), + ';', + ), + iteration_scheme: $ => choice( + seq( + reservedWord('while'), + field('condition', $.expression), + ), + seq( + reservedWord('for'), + choice( + $.loop_parameter_specification, + $.iterator_specification, + ), + ), +// seq( +// optional(reservedWord('parallel')), +// reservedWord('for'), +// $.procedural_iterator, +// ), +// seq( +// reservedWord('parallel'), +// optional(seq( +// '(', +// $.chunk_specification, +// ')', +// )), +// reservedWord('for'), +// choice( +// $.loop_parameter_specification, +// $.iterator_specification, +// ), +// ), + ), assignment_statement: $ => seq( $.name, $.assign_value,