Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port to ada_toml for TOML 1.0 #836

Merged
merged 2 commits into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deps/ada-toml
Submodule ada-toml updated 42 files
+9 −6 README.rst
+23 −3 run-tests.py
+5 −5 src-checkers/ada_toml_decode.adb
+3 −3 src-checkers/ada_toml_encode.adb
+33 −8 src/toml-generic_dump.adb
+192 −50 src/toml-generic_parse.adb
+25 −73 src/toml.adb
+20 −36 src/toml.ads
+24 −19 test-importers/burntsushi-toml-test.py
+28 −1 tests/api/merge/main.adb
+5 −0 tests/api/merge/test.out
+1 −0 tests/control-chars/input.toml
+2 −0 tests/control-chars/test.yaml
+2 −0 tests/datetime/valid/input.toml
+24 −22 tests/datetime/valid/test.yaml
+1 −0 tests/float/missing-first-digit/input.toml
+2 −0 tests/float/missing-first-digit/test.yaml
+1 −0 tests/integer/non-decimal-minus/input.toml
+2 −0 tests/integer/non-decimal-minus/test.yaml
+1 −0 tests/integer/non-decimal-plus/input.toml
+2 −0 tests/integer/non-decimal-plus/test.yaml
+1 −0 tests/integer/underscore-after-base/input.toml
+2 −0 tests/integer/underscore-after-base/test.yaml
+9 −1 tests/sections/heterogeneous-array/test.yaml
+2 −0 tests/sections/key-multiline/input.toml
+2 −0 tests/sections/key-multiline/test.yaml
+1 −1 tests/strings/escapes/input.toml
+1 −1 tests/strings/escapes/test.yaml
+2 −0 tests/strings/invalid-backslash-space/input.toml
+2 −0 tests/strings/invalid-backslash-space/test.yaml
+8 −0 tests/strings/multiline-ambiguous-closing/input.toml
+11 −0 tests/strings/multiline-ambiguous-closing/test.yaml
+1 −0 tests/strings/tab/input.toml
+4 −0 tests/strings/tab/test.yaml
+1 −0 tests/tables/nested-empty/input.toml
+14 −0 tests/tables/nested-empty/test.yaml
+1 −0 tests/tables/trailing-comma/input.toml
+2 −0 tests/tables/trailing-comma/test.yaml
+0 −0 tests/tables/valid/input.toml
+0 −0 tests/tables/valid/test.yaml
+1 −0 tests/token-1-sloc/input.toml
+2 −0 tests/token-1-sloc/test.yaml
2 changes: 1 addition & 1 deletion src/alire/alire-conditional_trees.adb
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ package body Alire.Conditional_Trees is
begin
case Current.Kind is
when TOML_Table =>
Table.Set (Key, TOML.Merge (Current, Val));
Table.Set (Key, TOML_Adapters.Merge_Tables (Current, Val));
when TOML_Array =>
case Val.Kind is
when TOML.Atom_Value_Kind | TOML.TOML_Table =>
Expand Down
2 changes: 1 addition & 1 deletion src/alire/alire-dependencies-states-maps.adb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ package body Alire.Dependencies.States.Maps is
-- Stored as an array of individual states:
-- [[state]]
begin
return Arr : constant TOML_Value := Create_Array (TOML_Table) do
return Arr : constant TOML_Value := Create_Array do
for Dep of This loop
Arr.Append (Dep.To_TOML);
end loop;
Expand Down
9 changes: 6 additions & 3 deletions src/alire/alire-origins.adb
Original file line number Diff line number Diff line change
Expand Up @@ -706,11 +706,14 @@ package body Alire.Origins is
+(Prefixes (This.Kind).all & (+This.Data.Description)));

when Binary_Archive =>
Table := TOML.Merge (Table,
This.Data.Bin_Archive.As_Data.To_TOML);
Table := TOML_Adapters.Merge_Tables
(Table,
This.Data.Bin_Archive.As_Data.To_TOML);

when Source_Archive =>
Table := TOML.Merge (Table, This.Data.Src_Archive.To_TOML);
Table := TOML_Adapters.Merge_Tables
(Table,
This.Data.Src_Archive.To_TOML);

when System =>
Table.Set (Keys.URL,
Expand Down
26 changes: 9 additions & 17 deletions src/alire/alire-properties-configurations.adb
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,11 @@ package body Alire.Properties.Configurations is
Res : Unbounded_String;
First : Boolean := True;
begin
if Str_Array.Kind /= TOML_Array
and then
Str_Array.Item_Kind /= TOML_String
then
raise Program_Error with "Invalid TOML kind for enum values";
end if;

for Index in 1 .. Str_Array.Length loop
if Str_Array.Item (Index).Kind /= TOML_String then
raise Program_Error with "Invalid TOML kind for enum values";
end if;

declare
Val : constant String := Str_Array.Item (Index).As_String;
Val_Str : constant Unbounded_String := +(if Wrap_With_Quotes
Expand Down Expand Up @@ -137,12 +134,8 @@ package body Alire.Properties.Configurations is
return Image (Val.As_Integer);

when TOML_Array =>
if Val.Item_Kind /= TOML_String then
Raise_Checked_Error ("Unexpected kind '" & Val.Item_Kind'Img &
"' in array conversion to String");
else
return To_String (Val);
end if;
-- Type of elements is checked inside following call
return To_String (Val);
when others =>
Raise_Checked_Error ("Unexpected kind '" & Val.Kind'Img &
"' in conversion to String");
Expand Down Expand Up @@ -700,10 +693,9 @@ package body Alire.Properties.Configurations is
when Enum =>
if From.Pop ("values", Type_Def.Values) then
if Type_Def.Values.Kind /= TOML_Array
or else
not Type_Def.Values.Item_Kind_Set
or else
Type_Def.Values.Item_Kind /= TOML_String
or else Type_Def.Values.Length = 0
or else (for some I in 1 .. Type_Def.Values.Length =>
Type_Def.Values.Item (I).Kind /= TOML_String)
then
From.Checked_Error
("'values' must be a not empty array of strings");
Expand Down
34 changes: 17 additions & 17 deletions src/alire/alire-properties-scenarios.adb
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,22 @@ package body Alire.Properties.Scenarios is
Table.Checked_Error
("At least two values required in scenario");
end if;
if Val.Item_Kind = TOML_String then
declare
use GPR;
Values : GPR.Value_Vector;
begin
for I in 1 .. Val.Length loop
Values := Values or Val.Item (I).As_String;
end loop;
Props := Props and New_Property
(GPR.Enum_Variable (Key, Values));
end;
else
Table.Checked_Error
("scenario values must be a string array");
end if;

declare
use GPR;
Values : GPR.Value_Vector;
begin
for I in 1 .. Val.Length loop
if Val.Item (I).Kind /= TOML_String then
Table.Checked_Error
("scenario values must be a string array");
end if;

Values := Values or Val.Item (I).As_String;
end loop;
Props := Props and New_Property
(GPR.Enum_Variable (Key, Values));
end;
end if;
end;
end loop;
Expand Down Expand Up @@ -143,8 +144,7 @@ package body Alire.Properties.Scenarios is
case V.Var.Element.Kind is
when Enumeration =>
declare
Arr : constant TOML.TOML_Value :=
TOML.Create_Array (TOML.TOML_String);
Arr : constant TOML.TOML_Value := TOML.Create_Array;
begin
for Val of V.Var.Element.Values loop
Arr.Append (+Val);
Expand Down
26 changes: 25 additions & 1 deletion src/alire/alire-toml_adapters.adb
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,30 @@ package body Alire.TOML_Adapters is
Context : String) return Key_Queue is
(From (Value, Context));

------------------
-- Merge_Tables --
------------------

function Merge_Tables (L, R : TOML.TOML_Value) return TOML.TOML_Value
is
use TOML;
function Merge_Internal (Key : Unbounded_UTF8_String;
L, R : TOML_Value)
return TOML_Value
is
pragma Unreferenced (Key);
begin
if L.Kind = TOML_Table and then R.Kind = L.Kind then
return TOML.Merge (L, R, Merge_Internal'Access);
else
Raise_Checked_Error
("Ill-shaped TOML information cannot be merged");
end if;
end Merge_Internal;
begin
return TOML.Merge (L, R, Merge_Entries => Merge_Internal'Access);
end Merge_Tables;

---------
-- Pop --
---------
Expand Down Expand Up @@ -374,7 +398,7 @@ package body Alire.TOML_Adapters is
return V;
else
declare
Arr : constant TOML_Value := Create_Array (V.Kind);
Arr : constant TOML_Value := Create_Array;
begin
Arr.Append (V);
return Arr;
Expand Down
4 changes: 4 additions & 0 deletions src/alire/alire-toml_adapters.ads
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ package Alire.TOML_Adapters with Preelaborate is
Pre => Val.Kind = TOML.TOML_Array;
-- Take a TOML value and turn it into a vector of strings

function Merge_Tables (L, R : TOML.TOML_Value) return TOML.TOML_Value with
Pre => L.Kind in TOML.TOML_Table and then R.Kind in TOML.TOML_Table,
Post => Merge_Tables'Result.Kind in TOML.TOML_Table;

generic
type Enum is (<>);
function Tomify_Enum (E : Enum) return TOML.TOML_Value;
Expand Down