@@ -1556,6 +1556,15 @@ package body Langkit_Support.Generic_API.Unparsing is
1556
1556
-- Using the unparsing configuration for N, unparse it to a Prettier
1557
1557
-- document.
1558
1558
1559
+ function Unparse_Field
1560
+ (Node : Lk_Node;
1561
+ Node_Config : Node_Config_Record;
1562
+ Child : Lk_Node;
1563
+ Field_Ref : Struct_Member_Index) return Document_Type;
1564
+ -- Unparse ``Child``, which is the ``Field_Ref`` field of ``Node``.
1565
+ -- ``Node_Config`` must be the node unparsing configuration for
1566
+ -- ``Node``.
1567
+
1559
1568
-- ----------------
1560
1569
-- Unparse_Node --
1561
1570
-- ----------------
@@ -1602,22 +1611,12 @@ package body Langkit_Support.Generic_API.Unparsing is
1602
1611
end ;
1603
1612
1604
1613
when Field_Fragment =>
1605
- declare
1606
- Field : constant Document_Type :=
1607
- Unparse_Node (F.Node);
1608
- Template : constant Template_Type :=
1609
- Node_Config.Field_Configs.Element (To_Index (F.Field));
1610
- Args : constant Template_Instantiation_Args :=
1611
- (Kind => With_Recurse, With_Recurse_Doc => Field);
1612
- begin
1613
- pragma Assert (Template.Kind = With_Recurse);
1614
- Items.Append
1615
- (Instantiate_Template
1616
- (Pool => Pool,
1617
- Node => N,
1618
- Template => Template,
1619
- Arguments => Args));
1620
- end ;
1614
+ Items.Append
1615
+ (Unparse_Field
1616
+ (Node => N,
1617
+ Node_Config => Node_Config,
1618
+ Child => F.Node,
1619
+ Field_Ref => To_Index (F.Field)));
1621
1620
1622
1621
when List_Child_Fragment =>
1623
1622
Items.Append (Unparse_Node (F.Node));
@@ -1669,7 +1668,12 @@ package body Langkit_Support.Generic_API.Unparsing is
1669
1668
Process_Fragment (Fragment_For (Id, T));
1670
1669
end loop ;
1671
1670
1672
- Items.Append (Unparse_Node (Child));
1671
+ Items.Append
1672
+ (Unparse_Field
1673
+ (Node => N,
1674
+ Node_Config => Node_Config,
1675
+ Child => Child,
1676
+ Field_Ref => Field_Unparser.Member));
1673
1677
1674
1678
for T of Field_Unparser.Post_Tokens.all loop
1675
1679
Process_Fragment (Fragment_For (Id, T));
@@ -1690,6 +1694,31 @@ package body Langkit_Support.Generic_API.Unparsing is
1690
1694
end case ;
1691
1695
end Unparse_Node ;
1692
1696
1697
+ -- -----------------
1698
+ -- Unparse_Field --
1699
+ -- -----------------
1700
+
1701
+ function Unparse_Field
1702
+ (Node : Lk_Node;
1703
+ Node_Config : Node_Config_Record;
1704
+ Child : Lk_Node;
1705
+ Field_Ref : Struct_Member_Index) return Document_Type
1706
+ is
1707
+ Field_Template : constant Template_Type :=
1708
+ Node_Config.Field_Configs.Element (Field_Ref);
1709
+ pragma Assert (Field_Template.Kind = With_Recurse);
1710
+
1711
+ Field_Template_Args : constant Template_Instantiation_Args :=
1712
+ (Kind => With_Recurse,
1713
+ With_Recurse_Doc => Unparse_Node (Child));
1714
+ begin
1715
+ return Instantiate_Template
1716
+ (Pool => Pool,
1717
+ Node => Node,
1718
+ Template => Field_Template,
1719
+ Arguments => Field_Template_Args);
1720
+ end Unparse_Field ;
1721
+
1693
1722
begin
1694
1723
if Config.Value = null then
1695
1724
raise Precondition_Failure with " null unparsing configuration" ;
0 commit comments