11-- ----------------------------------------------------------------------------
22-- Language Server Protocol --
33-- --
4- -- Copyright (C) 2018-2023 , AdaCore --
4+ -- Copyright (C) 2018-2024 , AdaCore --
55-- --
66-- This is free software; you can redistribute it and/or modify it under --
77-- terms of the GNU General Public License as published by the Free Soft- --
@@ -35,13 +35,18 @@ package body Tester.Macros is
3535 Test_Dir : String) return GNATCOLL.JSON.JSON_Value;
3636 -- Expand recursively
3737
38+ function Expand_FILE
39+ (Path : String;
40+ Test_Dir : String) return String;
41+ -- Turn Path into file absolute path
42+
3843 function Expand_URI
3944 (Path : String;
4045 Test_Dir : String) return String;
4146 -- Turn Path into URI with scheme 'file://'
4247
4348 Pattern : constant GNAT.Regpat.Pattern_Matcher :=
44- GNAT.Regpat.Compile (" \${([\w]+)}|\$URI{([^}]*)}" );
49+ GNAT.Regpat.Compile (" \${([\w]+)}|\$URI{([^}]*)}|\$FILE{([^}]*)} " );
4550
4651 Replace_Slash : constant Ada.Strings.Maps.Character_Mapping :=
4752 Ada.Strings.Maps.To_Mapping
@@ -91,7 +96,7 @@ package body Tester.Macros is
9196 begin
9297 while Next < Text'Length loop
9398 declare
94- Found : GNAT.Regpat.Match_Array (0 .. 2 );
99+ Found : GNAT.Regpat.Match_Array (0 .. 3 );
95100 begin
96101 GNAT.Regpat.Match (Pattern, Text, Found, Next);
97102 exit when Found (0 ) = GNAT.Regpat.No_Match;
@@ -116,6 +121,12 @@ package body Tester.Macros is
116121 Expand_URI
117122 (Text (Found (2 ).First .. Found (2 ).Last),
118123 Test_Dir));
124+ elsif Found (3 ) /= GNAT.Regpat.No_Match then -- $FILE{x}
125+ Append
126+ (Result,
127+ Expand_FILE
128+ (Text (Found (3 ).First .. Found (3 ).Last),
129+ Test_Dir));
119130 end if ;
120131
121132 Next := Found (0 ).Last + 1 ;
@@ -191,11 +202,11 @@ package body Tester.Macros is
191202 Test := Expand (Test, Env_With_Dir, Directory);
192203 end Expand ;
193204
194- -- --------------
195- -- Expand_URI --
196- -- --------------
205+ -- ---------------
206+ -- Expand_FILE --
207+ -- ---------------
197208
198- function Expand_URI
209+ function Expand_FILE
199210 (Path : String;
200211 Test_Dir : String) return String
201212 is
@@ -204,22 +215,31 @@ package body Tester.Macros is
204215 begin
205216 if Path = " " then
206217 -- Return normalized Test_Dir
207- return URIs.Conversions.From_File
208- (Ada.Directories.Full_Name (Test_Dir));
218+ return Ada.Directories.Full_Name (Test_Dir);
209219
210220 elsif Path = " /" then
211221 -- Return normalized Test_Dir & '/'
212- return URIs.Conversions.From_File
213- (Ada.Directories.Full_Name (Test_Dir) &
214- GNAT.OS_Lib.Directory_Separator);
222+ return Ada.Directories.Full_Name (Test_Dir) &
223+ GNAT.OS_Lib.Directory_Separator;
215224
216225 else
217226 -- Turn a relative path into absolute path
218- return URIs.Conversions.From_File
219- (Ada.Directories.Full_Name (Test_Dir) &
220- GNAT.OS_Lib.Directory_Separator &
221- Argument);
227+ return Ada.Directories.Full_Name (Test_Dir) &
228+ GNAT.OS_Lib.Directory_Separator &
229+ Argument;
222230 end if ;
231+ end Expand_FILE ;
232+
233+ -- --------------
234+ -- Expand_URI --
235+ -- --------------
236+
237+ function Expand_URI
238+ (Path : String;
239+ Test_Dir : String) return String
240+ is
241+ begin
242+ return URIs.Conversions.From_File (Expand_FILE (Path, Test_Dir));
223243 end Expand_URI ;
224244
225245end Tester.Macros ;
0 commit comments