Skip to content
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 grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ list_or ::= ('|' | 'or') EVS_or
EVS_and ::= (EVS_Nested | VS) [and_list]
EVS_or ::= (EVS_Nested | VS) [or_list]
OP ::= '<' | '>' etc <comparison operators>
NEG ::= '!' | 'not'
NEG ::= '!' | '¬' | 'not'
22 changes: 19 additions & 3 deletions src/semantic_versioning-extended.adb
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,8 @@ package body Semantic_Versioning.Extended is
return List_Img;

when Negated =>
return "!(" & Img (Trees.First_Child (Pos)) & ")";
return (if Opts.Unicode then U ("¬") else "!")
& "(" & Img (Trees.First_Child (Pos)) & ")";
end case;
end Img;

Expand Down Expand Up @@ -378,6 +379,8 @@ package body Semantic_Versioning.Extended is
VS,
End_Of_Input);

Not_UChar : constant String := U ("¬");

I : Integer := Str'First; -- Next char to process
Err : Unbounded_String;

Expand Down Expand Up @@ -519,6 +522,14 @@ package body Semantic_Versioning.Extended is
return VS;
end if;

if Begins_With (Str (I .. Str'Last), Not_UChar) then
if not Opts.Unicode then
Error (U ("Unicode operator '¬' not allowed " &
"(Unicode option is disabled)"));
end if;
return Negation;
end if;

case Str (I) is
when '&' => return Ampersand;
when '(' => return Lparen;
Expand All @@ -531,6 +542,7 @@ package body Semantic_Versioning.Extended is
when others => return Unknown;
end case;
end Internal;

begin
return T : constant Tokens := Internal do
Trace ("Next token: " & T'Img);
Expand Down Expand Up @@ -561,6 +573,8 @@ package body Semantic_Versioning.Extended is
when Negation =>
if Is_Keyword ("not") then
Match ("not");
elsif Begins_With (Str (I .. Str'Last), Not_UChar) then
Match (Not_UChar);
else
Match ('!');
end if;
Expand Down Expand Up @@ -760,7 +774,9 @@ package body Semantic_Versioning.Extended is
-------------

function Value_U (Str : Wide_Wide_String;
Relaxed : Boolean := False) return Version_Set
is (Value (U (Str), Relaxed));
Relaxed : Boolean := False;
Opts : Basic.Options := Basic.Default_Options)
return Version_Set
is (Value (U (Str), Relaxed, Opts));

end Semantic_Versioning.Extended;
4 changes: 3 additions & 1 deletion src/semantic_versioning-extended.ads
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ package Semantic_Versioning.Extended with Preelaborate is
-- Options control parsing (Unicode for accepting Unicode operators)

function Value_U (Str : Wide_Wide_String;
Relaxed : Boolean := False) return Version_Set;
Relaxed : Boolean := False;
Opts : Basic.Options := Basic.Default_Options)
return Version_Set;

function Image (VS : Version_Set) return String;
-- Original image, as given to Value
Expand Down
1 change: 1 addition & 0 deletions tests/alire.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ semantic_versioning = { path = '..' }

[build-profiles]
semantic_versioning = 'validation'
semver_tests = 'validation'
3 changes: 3 additions & 0 deletions tests/src/semver_tests-negation.adb
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ begin
Assert
(X.Value ("!^1").Synthetic_Image = X.Value ("!(^1)").Synthetic_Image);
-- Equivalent

-- Alternate symbol
Assert (X.Is_In (V ("1.1"), X.Value_U ("¬1")));
end Semver_Tests.Negation;
16 changes: 16 additions & 0 deletions tests/src/semver_tests-options.adb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ begin
XVS1 := X.Value (U ("≥1.2.0"), Opts => Unicode_Opts);
Assert (X.Is_In (V1_2, XVS1), "Extended Unicode parsing failed");

XVS1 := X.Value_U ("¬1.2.0", Opts => Unicode_Opts);
Assert (not X.Is_In (V1_2, XVS1), "Extended Unicode negation parsing failed");

Assert (not X.Parse (U ("¬1.2.0"), Opts => No_Unicode_Opts).Valid,
"Parse should fail for Unicode negation when disabled");

-- Test Synthetic_Image with different options
XVS1 := X.Value (">=1.2.0 & /=1.2.5");
Assert (X.Synthetic_Image (XVS1, Opts => Unicode_Opts) =
Expand All @@ -104,6 +110,16 @@ begin
"Extended ASCII output failed: " &
X.Synthetic_Image (XVS1, Opts => No_Unicode_Opts));

XVS1 := X.Value ("!1.2.0");
Assert (X.Synthetic_Image (XVS1, Opts => Unicode_Opts) =
U ("¬(=1.2.0)"),
"Extended Unicode negation output failed: " &
X.Synthetic_Image (XVS1, Opts => Unicode_Opts));
Assert (X.Synthetic_Image (XVS1, Opts => No_Unicode_Opts) =
"!(=1.2.0)",
"Extended ASCII negation output failed: " &
X.Synthetic_Image (XVS1, Opts => No_Unicode_Opts));

-- Test Implicit_Equal with Extended
XVS1 := X.Value ("=1.2.0");
Assert (X.Synthetic_Image (XVS1, Opts => With_Implicit) = "1.2.0",
Expand Down
13 changes: 13 additions & 0 deletions tests/src/semver_tests-with_unicode.adb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
procedure Semver_Tests.With_Unicode is

Unicode_Opts : constant Basic.Options :=
(Unicode => True,
Word_Operators => False,
Implicit_Equal => False);

begin
Assert (X.Is_In (V ("1.1"), X.Value_U ("≠1")));
Assert (X.Is_In (V ("1.1"), X.Value_U ("≥1")));
Assert (X.Is_In (V ("1.1"), X.Value_U ("≤1.1")));

declare
XVS : constant X.Version_Set := X.Value_U ("¬1", Opts => Unicode_Opts);
begin
Assert (not X.Is_In (V ("1.0.0"), XVS));
Assert (X.Synthetic_Image (XVS, Opts => Unicode_Opts) = U ("¬(=1.0.0)"));
end;
end Semver_Tests.With_Unicode;