Skip to content

Commit abc6bef

Browse files
committed
Merge branch 'issue_756' into 'master'
Unparsing: add a "hardlineWithoutBreakParent" command Closes #756 See merge request eng/libadalang/langkit!1001
2 parents 8a98016 + d275644 commit abc6bef

File tree

7 files changed

+77
-4
lines changed

7 files changed

+77
-4
lines changed

langkit/support/langkit_support-generic_api-unparsing.adb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,8 @@ package body Langkit_Support.Generic_API.Unparsing is
394394
return Pool.Create_Break_Parent;
395395
elsif Value = "hardline" then
396396
return Pool.Create_Hard_Line;
397+
elsif Value = "hardlineWithoutBreakParent" then
398+
return Pool.Create_Hard_Line_Without_Break_Parent;
397399
elsif Value = "line" then
398400
return Pool.Create_Line;
399401
elsif Value = "recurse" then
@@ -880,6 +882,9 @@ package body Langkit_Support.Generic_API.Unparsing is
880882
when Hard_Line =>
881883
return Pool.Create_Hard_Line;
882884

885+
when Hard_Line_Without_Break_Parent =>
886+
return Pool.Create_Hard_Line_Without_Break_Parent;
887+
883888
when If_Break =>
884889
return Pool.Create_If_Break
885890
(Instantiate_Template

langkit/support/langkit_support-generic_api-unparsing.ads

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@ package Langkit_Support.Generic_API.Unparsing is
104104
--
105105
-- "breakParent"
106106
--
107-
-- * The "line"/"hardline"/"softline"/"literalline" templates yield the
108-
-- corresponding Prettier documents::
107+
-- * The "line"/"hardline"/"hardLineWithoutBreakPararent"/"softline"/
108+
-- "literalline" templates yield the corresponding Prettier documents::
109109
--
110110
-- "line"
111-
-- "hardlist"
112-
-- "softlist"
111+
-- "hardline"
112+
-- "hardlineWithoutBreakParent"
113+
-- "softline"
113114
-- "literalline"
114115
--
115116
-- * The "trim" template yields a "trim" Prettier Document::

langkit/support/langkit_support-prettier_utils.adb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ package body Langkit_Support.Prettier_Utils is
6464
when Hard_Line =>
6565
return 0;
6666

67+
when Hard_Line_Without_Break_Parent =>
68+
return 0;
69+
6770
when If_Break =>
6871
declare
6972
Count_Break : constant Natural :=
@@ -157,6 +160,9 @@ package body Langkit_Support.Prettier_Utils is
157160
when Hard_Line =>
158161
return Hard_Line;
159162

163+
when Hard_Line_Without_Break_Parent =>
164+
return Hard_Line_Without_Break_Parent;
165+
160166
when If_Break =>
161167
return If_Break
162168
(To_Prettier_Document (Document.If_Break_Contents),
@@ -351,6 +357,21 @@ package body Langkit_Support.Prettier_Utils is
351357
end return;
352358
end Create_Hard_Line;
353359

360+
-------------------------------------------
361+
-- Create_Hard_Line_Without_Break_Parent --
362+
-------------------------------------------
363+
364+
function Create_Hard_Line_Without_Break_Parent
365+
(Self : in out Document_Pool) return Document_Type
366+
is
367+
begin
368+
return Result : constant Document_Type :=
369+
new Document_Record (Kind => Hard_Line_Without_Break_Parent)
370+
do
371+
Self.Register (Result);
372+
end return;
373+
end Create_Hard_Line_Without_Break_Parent;
374+
354375
---------------------
355376
-- Create_If_Break --
356377
---------------------
@@ -655,6 +676,9 @@ package body Langkit_Support.Prettier_Utils is
655676
when Hard_Line =>
656677
Extend_Spacing (Last_Spacing, Newline);
657678

679+
when Hard_Line_Without_Break_Parent =>
680+
Extend_Spacing (Last_Spacing, Newline);
681+
658682
when If_Break =>
659683
declare
660684
LT_Break : Token_Kind_Ref := Last_Token;
@@ -837,6 +861,9 @@ package body Langkit_Support.Prettier_Utils is
837861
when Hard_Line =>
838862
Put_Line ("hardline");
839863

864+
when Hard_Line_Without_Break_Parent =>
865+
Put_Line ("hardlineWithoutBreakParent");
866+
840867
when If_Break =>
841868
Put_Line ("ifBreak:");
842869
if Document.If_Break_Group_Id /= No_Symbol then

langkit/support/langkit_support-prettier_utils.ads

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ private package Langkit_Support.Prettier_Utils is
5757
Fill,
5858
Group,
5959
Hard_Line,
60+
Hard_Line_Without_Break_Parent,
6061
If_Break,
6162
Indent,
6263
Line,
@@ -92,6 +93,9 @@ private package Langkit_Support.Prettier_Utils is
9293
when Hard_Line =>
9394
null;
9495

96+
when Hard_Line_Without_Break_Parent =>
97+
null;
98+
9599
when If_Break =>
96100
If_Break_Contents : Document_Type;
97101
If_Break_Flat_Contents : Document_Type;
@@ -183,6 +187,10 @@ private package Langkit_Support.Prettier_Utils is
183187
(Self : in out Document_Pool) return Document_Type;
184188
-- Return a ``Hard_Line`` node
185189

190+
function Create_Hard_Line_Without_Break_Parent
191+
(Self : in out Document_Pool) return Document_Type;
192+
-- Return a ``Hard_Line_Without_Break_Parent`` node
193+
186194
function Create_If_Break
187195
(Self : in out Document_Pool;
188196
Contents : Document_Type;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"node_configs": {
3+
"VarDecl": {
4+
"node": [
5+
"hardlineWithoutBreakParent",
6+
"recurse"
7+
]
8+
}
9+
}
10+
}

testsuite/tests/ada_api/unparsing/commands.adb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ begin
9999
Check ("cmd_fill.json");
100100
Check ("cmd_group.json");
101101
Check ("cmd_hardline.json");
102+
Check ("cmd_hardlinewithoutbreakparent.json");
102103
Check ("cmd_ifbreak.json");
103104
Check ("cmd_indent.json");
104105
Check ("cmd_line.json");

testsuite/tests/ada_api/unparsing/test.out

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,27 @@ Done.
323323
]
324324
}
325325

326+
== cmd_hardlinewithoutbreakparent.json ==
327+
328+
{
329+
"kind": "list",
330+
"list": [
331+
{
332+
"kind": "command",
333+
"command": {
334+
"command": "line",
335+
"literal": false,
336+
"soft": false,
337+
"hard": true
338+
}
339+
},
340+
{
341+
"kind": "text",
342+
"text": "var i:Int=0;"
343+
}
344+
]
345+
}
346+
326347
== cmd_ifbreak.json ==
327348

328349
{

0 commit comments

Comments
 (0)