Skip to content

Commit

Permalink
Add and fix multiple unparsing configs
Browse files Browse the repository at this point in the history
Add config for SelectStmt and fix related ones (TaskBody,
AcceptStmtWithStmts and AcceptStmt).
Fix CallStmt config so that a `f_name` is always followed by a
whitespace or line.
Fix concatenations inside association lists.
Add config for SubtypeIndication.
Improve IfExpr config.
Add config for NullRecordAggregate.
Fix f_type_expr indentation in ObjectDecl.
Improve RaiseStmt config.
  • Loading branch information
joaopsazevedo committed Aug 5, 2024
1 parent 5a4f88c commit 9fcb3d8
Show file tree
Hide file tree
Showing 27 changed files with 836 additions and 206 deletions.
823 changes: 619 additions & 204 deletions extensions/default_unparsing_config.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion testsuite/tests/unparsing/aggregate/long_complete/test.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Foo :=
(Baaaar with
(Baaaar
with
Qux => Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
Baaaz => Bazzzzzzzz);
11 changes: 11 additions & 0 deletions testsuite/tests/unparsing/call_stmt/concatenation/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Add_Attribute
(Package_Name => +"IDE",
Attribute_Name => +"Connection_Tool",
Description =>
"Executable used to interface with a "
& "remote target when debugging. GNAT Studio currently supports "
& "OpenOCD, st-util or pyOCD. You can leave this attribute empty "
& "if you are using a custom tool spawned outside of GNAT Studio'.",
Index_Type => PRA.No_Index,
Value => Single,
Value_Case_Sensitive => True);
11 changes: 11 additions & 0 deletions testsuite/tests/unparsing/call_stmt/concatenation/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Add_Attribute
(Package_Name => +"IDE",
Attribute_Name => +"Connection_Tool",
Description =>
"Executable used to interface with a "
& "remote target when debugging. GNAT Studio currently supports "
& "OpenOCD, st-util or pyOCD. You can leave this attribute empty "
& "if you are using a custom tool spawned outside of GNAT Studio'.",
Index_Type => PRA.No_Index,
Value => Single,
Value_Case_Sensitive => True);
4 changes: 4 additions & 0 deletions testsuite/tests/unparsing/call_stmt/concatenation/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: stmt
description: |
Test that multiple `ConcatOp`s inside `CallStmt` are correctly indented.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Foooo :
constant Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar
(Cooooooooooooooooooooooooooooorge) :=
Baaaaaaaaaaaaaaaaaaaaaaaaaz;

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Foooo :
constant Baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar
(Cooooooooooooooooooooooooooooorge) :=
Baaaaaaaaaaaaaaaaaaaaaaaaaz;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
driver: unparser
rule: object_decl
description: |
Test that when `f_type_expr` is long, a line break and continuation line
indentation is added after the `:`.
Also test that if `f_type_expr` is multi line, its indentation is relative
to where it starts.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
raise Some_Exception with "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA" & "AAAAAAAAAAAAAAAAAAAAAAAA"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
raise Some_Exception
with
"AAAAAAAAAAAAAAAAAAAAAAAA"
& "AAAAAAAAAAAAAAAAAAAAAAAA"
& "AAAAAAAAAAAAAAAAAAAAAAAA"
& "AAAAAAAAAAAAAAAAAAAAAAAA"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
driver: unparser
rule: raise_expr
description: |
This test checks the formatting of a `RaiseExpr` that has a long
`f_error_message` which consists of concatenations.
It is expected `f_error_message` to be continuation line indented relative to
`with`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
accept Driver_Awake_Signal;
or
delay 30.0 * Seconds;
Stop_The_Train;
end select;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
select
accept Driver_Awake_Signal;
or
delay 30.0 * Seconds;
Stop_The_Train;
end select;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
driver: unparser
rule: stmt
description: |
Test a `SelectStmt` node with a single element `f_guards` and single line
`AcceptStmt`.
It is expected that the `or` keyword is in its own line with the same
indentation as the `select` keyword.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
select
accept Start
(Data_To_Monitor : Data_To_Monitor_Access;
Directories : GNATCOLL.VFS.File_Array)
do
Data := Data_To_Monitor;

Monitor := new LSP_Monitor;
Monitor.The_Server := Data_To_Monitor.Server;

Dirs := new File_Array (1 .. Directories'Length);
Free_Index := 1;
for Dir of Directories loop
if Dir.Is_Directory then
Dirs (Free_Index) := Dir;
Free_Index := Free_Index + 1;
end if;
end loop;
end Start;
or
accept Stop do
Stop_Requested := True;
end Stop;
end select;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
select
accept Start
(Data_To_Monitor : Data_To_Monitor_Access;
Directories : GNATCOLL.VFS.File_Array)
do
Data := Data_To_Monitor;

Monitor := new LSP_Monitor;
Monitor.The_Server := Data_To_Monitor.Server;

Dirs := new File_Array (1 .. Directories'Length);
Free_Index := 1;
for Dir of Directories loop
if Dir.Is_Directory then
Dirs (Free_Index) := Dir;
Free_Index := Free_Index + 1;
end if;
end loop;
end Start;
or
accept Stop do
Stop_Requested := True;
end Stop;
end select;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
driver: unparser
rule: stmt
description: |
Test a `SelectStmt` node with a single element `f_guards` and multi line
`AcceptStmt`.
It is expected that the `or` keyword is in its own line with the same
indentation as the `select` keyword.
17 changes: 17 additions & 0 deletions testsuite/tests/unparsing/select_stmt/multiple_guards/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
task body Server is
Current_Work_Item : Work_Item;
begin
loop
select
accept Next_Work_Item (WI : in Work_Item) do
Current_Work_Item := WI;
end;
Process_Work_Item (Current_Work_Item);
or
accept Shut_Down;
exit; -- Premature shut down requested
or
terminate; -- Normal shutdown at end of scope
end select;
end loop;
end Server;
17 changes: 17 additions & 0 deletions testsuite/tests/unparsing/select_stmt/multiple_guards/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
task body Server is
Current_Work_Item : Work_Item;
begin
loop
select
accept Next_Work_Item (WI : in Work_Item) do
Current_Work_Item := WI;
end;
Process_Work_Item (Current_Work_Item);
or
accept Shut_Down;
exit; -- Premature shut down requested
or
terminate; -- Normal shutdown at end of scope
end select;
end loop;
end Server;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
driver: unparser
rule: task_body
description: |
Test a `SelectStmt` node with an `f_guards` of multiple guards.
It is expected that the `or` keywords are on their own lines with the same
indentation as the `select` keyword.
12 changes: 12 additions & 0 deletions testsuite/tests/unparsing/select_stmt/with_else/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
procedure Spin (R : in out Resource) is
begin
loop
select
Controller.Request (Medium) (Some_Item);
R.Seize;
return;
else
null; -- busy waiting
end select;
end loop;
end;
12 changes: 12 additions & 0 deletions testsuite/tests/unparsing/select_stmt/with_else/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
procedure Spin (R : in out Resource) is
begin
loop
select
Controller.Request (Medium) (Some_Item);
R.Seize;
return;
else
null; -- busy waiting
end select;
end loop;
end;
6 changes: 6 additions & 0 deletions testsuite/tests/unparsing/select_stmt/with_else/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
driver: unparser
rule: subp_body
description: |
Test a `SelectStmt` node with a non null `f_else_stmts`.
It is expected that the `else` keyword is in its own line with the same
indentation as the `select` keyword.
2 changes: 1 addition & 1 deletion testsuite/tests/unparsing/subunit/test.out
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
separate(Parent)
separate (Parent)
procedure Inner is
begin
Foo;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
type LCS_Array is
array (Natural range 0 .. Old_Length, Natural range 0 .. New_Length, Natural range 0 .. New_Length)
of Integer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type LCS_Array is
array (Natural range 0 .. Old_Length,
Natural range 0 .. New_Length,
Natural range 0 .. New_Length)
of Integer;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
driver: unparser
rule: type_decl
description: |
This test checks the formatting of a constrained array that has multiple
long constraints. It is expected the constraint list to be splitted in
multiple lines.

0 comments on commit 9fcb3d8

Please sign in to comment.