diff --git a/extensions/default_unparsing_config.json b/extensions/default_unparsing_config.json index 5edf4c471..933cf3df8 100644 --- a/extensions/default_unparsing_config.json +++ b/extensions/default_unparsing_config.json @@ -2294,6 +2294,13 @@ ] } }, + "ExprAlternativesList": { + "sep": [ + "line", + "recurse", + "whitespace" + ] + }, "ExprFunction": { "node": { "kind": "group", @@ -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": [ { diff --git a/testsuite/tests/unparsing/membership_expr/f_op_in/input.ada b/testsuite/tests/unparsing/membership_expr/f_op_in/input.ada new file mode 100644 index 000000000..ae5b84b85 --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/f_op_in/input.ada @@ -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); diff --git a/testsuite/tests/unparsing/membership_expr/f_op_in/test.out b/testsuite/tests/unparsing/membership_expr/f_op_in/test.out new file mode 100644 index 000000000..fdc0709d8 --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/f_op_in/test.out @@ -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); diff --git a/testsuite/tests/unparsing/membership_expr/f_op_in/test.yaml b/testsuite/tests/unparsing/membership_expr/f_op_in/test.yaml new file mode 100644 index 000000000..691bd9f95 --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/f_op_in/test.yaml @@ -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. diff --git a/testsuite/tests/unparsing/membership_expr/f_op_not_in/input.ada b/testsuite/tests/unparsing/membership_expr/f_op_not_in/input.ada new file mode 100644 index 000000000..59ef7c1ff --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/f_op_not_in/input.ada @@ -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; diff --git a/testsuite/tests/unparsing/membership_expr/f_op_not_in/test.out b/testsuite/tests/unparsing/membership_expr/f_op_not_in/test.out new file mode 100644 index 000000000..bea2e0541 --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/f_op_not_in/test.out @@ -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; diff --git a/testsuite/tests/unparsing/membership_expr/f_op_not_in/test.yaml b/testsuite/tests/unparsing/membership_expr/f_op_not_in/test.yaml new file mode 100644 index 000000000..bbd389ab7 --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/f_op_not_in/test.yaml @@ -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. diff --git a/testsuite/tests/unparsing/membership_expr/short/input.ada b/testsuite/tests/unparsing/membership_expr/short/input.ada new file mode 100644 index 000000000..adf50c754 --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/short/input.ada @@ -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); diff --git a/testsuite/tests/unparsing/membership_expr/short/test.out b/testsuite/tests/unparsing/membership_expr/short/test.out new file mode 100644 index 000000000..c3c515332 --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/short/test.out @@ -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); diff --git a/testsuite/tests/unparsing/membership_expr/short/test.yaml b/testsuite/tests/unparsing/membership_expr/short/test.yaml new file mode 100644 index 000000000..cb0336d9e --- /dev/null +++ b/testsuite/tests/unparsing/membership_expr/short/test.yaml @@ -0,0 +1,4 @@ +driver: unparser +rule: expr_fn +description: | + Test that no line breaks are added when `MembershipExpr`s fits on the line.