Skip to content

Commit

Permalink
Unparsing: add configuration for ExitStmt, GotoStmt and NamedStmt
Browse files Browse the repository at this point in the history
  • Loading branch information
joaopsazevedo committed Mar 27, 2024
1 parent 25bb9dd commit 3fe6e89
Show file tree
Hide file tree
Showing 25 changed files with 561 additions and 0 deletions.
84 changes: 84 additions & 0 deletions extensions/default_unparsing_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1479,6 +1479,46 @@
}
}
},
"ExitStmt": {
"node": {
"kind": "group",
"document": [
{
"kind": "text",
"text": "exit"
},
{
"kind": "recurse_field",
"field": "f_loop_name"
},
{
"kind": "recurse_field",
"field": "f_cond_expr"
},
{
"kind": "text",
"text": ";"
}
]
},
"fields": {
"f_cond_expr": [
"whitespace",
{
"kind": "text",
"text": "when"
},
{
"kind": "align",
"width": 2,
"contents": [
"line",
"recurse"
]
}
]
}
},
"ExprFunction": {
"node": {
"kind": "group",
Expand Down Expand Up @@ -1749,6 +1789,30 @@
"document": "recurse"
}
},
"GotoStmt": {
"node": {
"kind": "group",
"document": {
"kind": "align",
"width": 2,
"contents": [
{
"kind": "text",
"text": "goto"
},
"line",
{
"kind": "recurse_field",
"field": "f_label_name"
},
{
"kind": "text",
"text": ";"
}
]
}
}
},
"ForLoopIterFilter": {
"node": {
"kind": "group",
Expand Down Expand Up @@ -2567,6 +2631,26 @@
]
}
},
"NamedStmt": {
"node": {
"kind": "group",
"document": [
{
"kind": "recurse_field",
"field": "f_decl"
},
{
"kind": "text",
"text": ":"
},
"hardlineWithoutBreakParent",
{
"kind": "recurse_field",
"field": "f_stmt"
}
]
}
},
"NameList": {
"sep": [
"recurse",
Expand Down
104 changes: 104 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/long/doc-baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
{
"id": 13,
"kind": "command",
"command": {
"command": "group",
"id": 0,
"groupContents": {
"id": 12,
"kind": "list",
"list": [
{
"id": 0,
"kind": "text",
"text": "exit Quuux when"
},
{
"id": 10,
"kind": "command",
"command": {
"command": "align",
"alignData": {
"kind": "width",
"n": 2
},
"alignContents": {
"id": 9,
"kind": "list",
"list": [
{
"id": 1,
"kind": "command",
"command": {
"command": "line",
"literal": false,
"soft": false,
"hard": false
}
},
{
"id": 8,
"kind": "command",
"command": {
"command": "group",
"id": 0,
"groupContents": {
"id": 7,
"kind": "list",
"list": [
{
"id": 2,
"kind": "text",
"text": "Foooooooooooooooooooooooooooooooooooooooooooooooooooooo"
},
{
"id": 3,
"kind": "command",
"command": {
"command": "line",
"literal": false,
"soft": false,
"hard": false
}
},
{
"id": 4,
"kind": "text",
"text": "and then "
},
{
"id": 6,
"kind": "command",
"command": {
"command": "align",
"alignData": {
"kind": "innerRoot"
},
"alignContents": {
"id": 5,
"kind": "text",
"text": "Baaaaaaaaaar"
}
}
}
]
},
"break": false,
"expandedStates": null
}
}
]
}
}
},
{
"id": 11,
"kind": "text",
"text": ";"
}
]
},
"break": false,
"expandedStates": null
}
}
2 changes: 2 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/long/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
exit Quuux when Foooooooooooooooooooooooooooooooooooooooooooooooooooooo and then Baaaaaaaaaar;

3 changes: 3 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/long/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
exit Quuux when
Foooooooooooooooooooooooooooooooooooooooooooooooooooooo
and then Baaaaaaaaaar;
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/long/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: exit_stmt
description: |
Test the line break after the `when` keyword and the continuation line
indentation of `f_cond_expr`.
21 changes: 21 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/no_when/doc-baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"id": 2,
"kind": "command",
"command": {
"command": "group",
"id": 0,
"groupContents": {
"id": 1,
"kind": "list",
"list": [
{
"id": 0,
"kind": "text",
"text": "exit;"
}
]
},
"break": false,
"expandedStates": null
}
}
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/exit_stmt/no_when/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit;
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/exit_stmt/no_when/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit;
4 changes: 4 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/no_when/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: exit_stmt
description: |
Test that no line breaks were added.
58 changes: 58 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/short/doc-baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"id": 7,
"kind": "command",
"command": {
"command": "group",
"id": 0,
"groupContents": {
"id": 6,
"kind": "list",
"list": [
{
"id": 0,
"kind": "text",
"text": "exit when"
},
{
"id": 4,
"kind": "command",
"command": {
"command": "align",
"alignData": {
"kind": "width",
"n": 2
},
"alignContents": {
"id": 3,
"kind": "list",
"list": [
{
"id": 1,
"kind": "command",
"command": {
"command": "line",
"literal": false,
"soft": false,
"hard": false
}
},
{
"id": 2,
"kind": "text",
"text": "Foo"
}
]
}
}
},
{
"id": 5,
"kind": "text",
"text": ";"
}
]
},
"break": false,
"expandedStates": null
}
}
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/exit_stmt/short/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit when Foo;
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/exit_stmt/short/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exit when Foo;
4 changes: 4 additions & 0 deletions testsuite/tests/unparsing/exit_stmt/short/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
driver: unparser
rule: exit_stmt
description: |
Test that no line breaks were added.
47 changes: 47 additions & 0 deletions testsuite/tests/unparsing/goto_stmt/long/doc-baseline.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"id": 5,
"kind": "command",
"command": {
"command": "group",
"id": 0,
"groupContents": {
"id": 4,
"kind": "command",
"command": {
"command": "align",
"alignData": {
"kind": "width",
"n": 2
},
"alignContents": {
"id": 3,
"kind": "list",
"list": [
{
"id": 0,
"kind": "text",
"text": "goto"
},
{
"id": 1,
"kind": "command",
"command": {
"command": "line",
"literal": false,
"soft": false,
"hard": false
}
},
{
"id": 2,
"kind": "text",
"text": "Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo;"
}
]
}
}
},
"break": false,
"expandedStates": null
}
}
1 change: 1 addition & 0 deletions testsuite/tests/unparsing/goto_stmt/long/input.ada
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
goto Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo;
2 changes: 2 additions & 0 deletions testsuite/tests/unparsing/goto_stmt/long/test.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
goto
Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo;
5 changes: 5 additions & 0 deletions testsuite/tests/unparsing/goto_stmt/long/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
driver: unparser
rule: goto_stmt
description: |
Test the line break after the `goto` keyword and the continuation line
indentation of `f_label_name`.
Loading

0 comments on commit 3fe6e89

Please sign in to comment.