Support for loop statements
This commit is contained in:
parent
ad302a74a2
commit
2db1b28fb6
|
|
@ -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;
|
||||
|
|
@ -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
|
||||
|
|
@ -156,9 +162,9 @@ end;
|
|||
(name
|
||||
(identifier)))))))
|
||||
|
||||
==========================
|
||||
================================================================================
|
||||
private types
|
||||
=========================
|
||||
================================================================================
|
||||
|
||||
package P is
|
||||
type A is private;
|
||||
|
|
@ -166,9 +172,9 @@ package P is
|
|||
type C is abstract tagged limited private with Size => 8;
|
||||
end;
|
||||
|
||||
-----------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(package_specification
|
||||
(name
|
||||
|
|
@ -199,9 +205,9 @@ end;
|
|||
(primary
|
||||
(numeric_literal))))))))))))))))
|
||||
|
||||
==========
|
||||
================================================================================
|
||||
incomplete types
|
||||
==========
|
||||
================================================================================
|
||||
|
||||
package P is
|
||||
private
|
||||
|
|
@ -211,9 +217,9 @@ private
|
|||
type T is tagged;
|
||||
end;
|
||||
|
||||
--------------
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
(compilation
|
||||
(compilation
|
||||
(compilation_unit
|
||||
(package_specification
|
||||
(name
|
||||
|
|
@ -240,4 +246,3 @@ end;
|
|||
(type_declaration
|
||||
(incomplete_type_declaration
|
||||
(identifier))))))
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,8 @@ end P;
|
|||
(identifier))
|
||||
(name
|
||||
(identifier)
|
||||
(identifier)))))
|
||||
(name
|
||||
(identifier))))))
|
||||
(declarative_item_pragma
|
||||
(renaming_declaration
|
||||
(subprogram_renaming_declaration
|
||||
|
|
|
|||
263
corpus/statements.txt
Normal file
263
corpus/statements.txt
Normal file
|
|
@ -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>>
|
||||
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))))))
|
||||
136
grammar.js
136
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(
|
||||
name: $ => choice(
|
||||
seq(
|
||||
$._direct_name,
|
||||
repeat(seq(
|
||||
optional(seq(
|
||||
'.',
|
||||
$.identifier,
|
||||
$.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,
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user