Skip to content

Commit

Permalink
Merge branch 'gnatformat-issue_51' into 'master'
Browse files Browse the repository at this point in the history
Unparsing: Add config for MembershipExpr and ExprAlternativesList

Closes eng/ide/gnatformat#51

See merge request eng/libadalang/libadalang!1716
  • Loading branch information
joaopsazevedo committed Jul 30, 2024
2 parents cc3af8d + a599bb2 commit 1ca4518
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 0 deletions.
56 changes: 56 additions & 0 deletions extensions/default_unparsing_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,13 @@
]
}
},
"ExprAlternativesList": {
"sep": [
"line",
"recurse",
"whitespace"
]
},
"ExprFunction": {
"node": {
"kind": "group",
Expand Down Expand Up @@ -3616,6 +3623,55 @@
]
}
},
"MembershipExpr": {
"node": {
"kind": "innerRoot",
"contents": {
"kind": "group",
"document": [
{
"kind": "group",
"document": [
{
"kind": "recurse_field",
"field": "f_expr"
},
"line",
{
"kind": "recurse_field",
"field": "f_op"
}
],
"id": "expr_with_op"
},
{
"kind": "ifBreak",
"flatContents": {
"kind": "continuationLineIndent",
"contents": [
"line",
{
"kind": "recurse_field",
"field": "f_membership_exprs"
}
]
},
"breakContents": [
"whitespace",
{
"kind": "innerRoot",
"contents": {
"kind": "recurse_field",
"field": "f_membership_exprs"
}
}
],
"groupId": "expr_with_op"
}
]
}
}
},
"ModeIn": {
"node": [
{
Expand Down
40 changes: 40 additions & 0 deletions testsuite/tests/unparsing/membership_expr/f_op_in/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
function Is_Expected_Parent_Kind (Kiiiiiind : Ada_Node_Kind_Type) return Boolean
is (Kiiiiiiiiind.Something_That_Is_Veeeeeeeeeeeeeeeeeeeeeeery_Looooooooooooooong
in Ada_Package_Body
| Ada_Package_Decl
| Ada_Library_Item
| Ada_Subp_Body
| Ada_Task_Body
| Ada_Decl_Block
| Ada_For_Loop_Stmt
| Ada_Loop_Stmt
| Ada_While_Loop_Stmt
| Ada_If_Stmt_Range
| Ada_Case_Stmt_Range
| Ada_Case_Stmt_Alternative_Range
and Kiiiiiiiiind.Something_That_Is_Veeeeeeeeeeeeeeeeeeeeeeery_Looooooooooooooong.Foooooooooooooooo in
Ada_Package_Body
| Ada_Package_Decl
| Ada_Library_Item
| Ada_Subp_Body
| Ada_Task_Body
| Ada_Decl_Block
| Ada_For_Loop_Stmt
| Ada_Loop_Stmt
| Ada_While_Loop_Stmt
| Ada_If_Stmt_Range
| Ada_Case_Stmt_Range
| Ada_Case_Stmt_Alternative_Range
and Kiiiiiiiiind in
Ada_Package_Body
| Ada_Package_Decl
| Ada_Library_Item
| Ada_Subp_Body
| Ada_Task_Body
| Ada_Decl_Block
| Ada_For_Loop_Stmt
| Ada_Loop_Stmt
| Ada_While_Loop_Stmt
| Ada_If_Stmt_Range
| Ada_Case_Stmt_Range
| Ada_Case_Stmt_Alternative_Range);
44 changes: 44 additions & 0 deletions testsuite/tests/unparsing/membership_expr/f_op_in/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function Is_Expected_Parent_Kind
(Kiiiiiind : Ada_Node_Kind_Type) return Boolean
is (Kiiiiiiiiind
.Something_That_Is_Veeeeeeeeeeeeeeeeeeeeeeery_Looooooooooooooong
in Ada_Package_Body
| Ada_Package_Decl
| Ada_Library_Item
| Ada_Subp_Body
| Ada_Task_Body
| Ada_Decl_Block
| Ada_For_Loop_Stmt
| Ada_Loop_Stmt
| Ada_While_Loop_Stmt
| Ada_If_Stmt_Range
| Ada_Case_Stmt_Range
| Ada_Case_Stmt_Alternative_Range
and Kiiiiiiiiind
.Something_That_Is_Veeeeeeeeeeeeeeeeeeeeeeery_Looooooooooooooong
.Foooooooooooooooo
in Ada_Package_Body
| Ada_Package_Decl
| Ada_Library_Item
| Ada_Subp_Body
| Ada_Task_Body
| Ada_Decl_Block
| Ada_For_Loop_Stmt
| Ada_Loop_Stmt
| Ada_While_Loop_Stmt
| Ada_If_Stmt_Range
| Ada_Case_Stmt_Range
| Ada_Case_Stmt_Alternative_Range
and Kiiiiiiiiind in
Ada_Package_Body
| Ada_Package_Decl
| Ada_Library_Item
| Ada_Subp_Body
| Ada_Task_Body
| Ada_Decl_Block
| Ada_For_Loop_Stmt
| Ada_Loop_Stmt
| Ada_While_Loop_Stmt
| Ada_If_Stmt_Range
| Ada_Case_Stmt_Range
| Ada_Case_Stmt_Alternative_Range);
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/membership_expr/f_op_in/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: subp_decl
description: |
Test that the `f_membership_exprs` field is correctly indented based on
`f_expr` when `f_op` is an `OpIn` node.
10 changes: 10 additions & 0 deletions testsuite/tests/unparsing/membership_expr/f_op_not_in/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
procedure Foo
is
begin
if Parent.Parent.Kind not in Ada_Begin_Block_Range | Ada_Decl_Block_Range | Bar
and then Parent_Parent.Parent_Parent.Parent_Parent.Parent_Kind not in Ada_Begin_Block_Range | Ada_Decl_Block_Range | Bar
and then Parent_Parent.Parent_Parent.Parent_Parent.Parent_Parent.Parent_Kind not in Ada_Begin_Block_Range | Ada_Decl_Block_Range | Bar
then
Current_Indentation := @ + Indentation;
end if;
end Foo;
22 changes: 22 additions & 0 deletions testsuite/tests/unparsing/membership_expr/f_op_not_in/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
procedure Foo is
begin
if Parent.Parent.Kind not in
Ada_Begin_Block_Range
| Ada_Decl_Block_Range
| Bar
and then Parent_Parent.Parent_Parent.Parent_Parent.Parent_Kind not in
Ada_Begin_Block_Range
| Ada_Decl_Block_Range
| Bar
and then Parent_Parent
.Parent_Parent
.Parent_Parent
.Parent_Parent
.Parent_Kind
not in Ada_Begin_Block_Range
| Ada_Decl_Block_Range
| Bar
then
Current_Indentation := @ + Indentation;
end if;
end Foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: subp_body
description: |
Test that the `f_membership_exprs` field is correctly indented based on
`f_expr` when `f_op` is an `OpNotIn` node.
2 changes: 2 additions & 0 deletions testsuite/tests/unparsing/membership_expr/short/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
function Is_Expected_Parent_Kind (Kind_1, Kind_2: Ada_Node_Kind_Type) return Boolean
is (Kind_1 in Ada_Package_Body and Kind_2 in Ada_Subp_Body);
3 changes: 3 additions & 0 deletions testsuite/tests/unparsing/membership_expr/short/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function Is_Expected_Parent_Kind
(Kind_1, Kind_2 : Ada_Node_Kind_Type) return Boolean
is (Kind_1 in Ada_Package_Body and Kind_2 in Ada_Subp_Body);
4 changes: 4 additions & 0 deletions testsuite/tests/unparsing/membership_expr/short/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: expr_fn
description: |
Test that no line breaks are added when `MembershipExpr`s fits on the line.

0 comments on commit 1ca4518

Please sign in to comment.