From cf6983dcde18e9a93c25f7bff313a6b19cfcd4f3 Mon Sep 17 00:00:00 2001 From: Steve Hancock Date: Tue, 23 Jul 2024 07:02:10 -0700 Subject: [PATCH] add support for new ^^ logical xor, see git #154 --- CHANGES.md | 7 +++++++ lib/Perl/Tidy/Formatter.pm | 4 ++-- lib/Perl/Tidy/Tokenizer.pm | 6 +++--- t/snippets/expect/logical_xor.def | 1 + t/snippets/logical_xor.in | 1 + t/snippets/packing_list.txt | 1 + t/snippets30.t | 13 +++++++++++++ 7 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 t/snippets/expect/logical_xor.def create mode 100644 t/snippets/logical_xor.in diff --git a/CHANGES.md b/CHANGES.md index 62289053..f95f9149 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,13 @@ ## 2024 05 11.06 + - Add logical xor operator ^^ available in perl version 5.40, as + noted in git #157. + + - Keyword 'state' now has default space before a paren, like 'my'. + Previously there was no space and no control. So the default + is now "state ($x)". This space can be removed with -nsak='state'. + - Add options --add-lone-trailing-commas, -altc and --delete-lone-trailing-commas, -dltc, to add control over adding and deleting the only comma in a list. See discussion in git #143 diff --git a/lib/Perl/Tidy/Formatter.pm b/lib/Perl/Tidy/Formatter.pm index 7fa1ae68..4e9af373 100644 --- a/lib/Perl/Tidy/Formatter.pm +++ b/lib/Perl/Tidy/Formatter.pm @@ -3072,7 +3072,7 @@ sub initialize_whitespace_hashes { my @spaces_both_sides = qw# + - * / % ? = . : x < > | & ^ .. << >> ** && .. || // => += -= .= %= x= &= |= ^= *= <> <= >= == =~ !~ /= != ... <<= >>= ~~ !~~ - **= &&= ||= //= <=> A k f w F n C Y U G v P S + **= &&= ||= //= <=> A k f w F n C Y U G v P S ^^ #; my @spaces_left_side = qw< @@ -4019,7 +4019,7 @@ EOM @q = qw( .. :: << >> ** && || // -> => += -= .= %= &= |= ^= *= <> - <= >= == =~ !~ != ++ -- /= x= ~~ ~. |. &. ^. + <= >= == =~ !~ != ++ -- /= x= ~~ ~. |. &. ^. ^^ ); @is_digraph{@q} = (1) x scalar(@q); diff --git a/lib/Perl/Tidy/Tokenizer.pm b/lib/Perl/Tidy/Tokenizer.pm index 20de7f84..bdacb464 100644 --- a/lib/Perl/Tidy/Tokenizer.pm +++ b/lib/Perl/Tidy/Tokenizer.pm @@ -10727,7 +10727,7 @@ For the following tokens, the "type" of a token is just the token itself. .. :: << >> ** && .. || // -> => += -= .= %= &= |= ^= *= <> ( ) <= >= == =~ !~ != ++ -- /= x= ... **= <<= >>= &&= ||= //= <=> -, + - / * | % ! x ~ = \ ? : . < > ^ & +, + - / * | % ! x ~ = \ ? : . < > ^ & ^^ The following additional token types are defined: @@ -10890,7 +10890,7 @@ BEGIN { my @digraphs = qw( .. :: << >> ** && || // -> => += -= .= %= &= |= ^= *= <> - <= >= == =~ !~ != ++ -- /= x= ~~ ~. |. &. ^. + <= >= == =~ !~ != ++ -- /= x= ~~ ~. |. &. ^. ^^ ); @is_digraph{@digraphs} = (1) x scalar(@digraphs); @@ -11270,7 +11270,7 @@ BEGIN { **= += -= .= /= *= %= x= &= |= ^= <<= >>= &&= ||= //= <= >= == != => \ > < % * / ? & | ** <=> ~~ !~~ <<~ f F pp mm Y p m U J G j >> << ^ t - ~. ^. |. &. ^.= |.= &.= + ~. ^. |. &. ^.= |.= &.= ^^ #; push( @value_requestor_type, ',' ) ; # (perl doesn't like a ',' in a qw block) diff --git a/t/snippets/expect/logical_xor.def b/t/snippets/expect/logical_xor.def new file mode 100644 index 00000000..8670e810 --- /dev/null +++ b/t/snippets/expect/logical_xor.def @@ -0,0 +1 @@ +$x ^^ $y and say "One of x or y is true, but not both"; diff --git a/t/snippets/logical_xor.in b/t/snippets/logical_xor.in new file mode 100644 index 00000000..49b32256 --- /dev/null +++ b/t/snippets/logical_xor.in @@ -0,0 +1 @@ +$x^^$y and say "One of x or y is true, but not both"; diff --git a/t/snippets/packing_list.txt b/t/snippets/packing_list.txt index 97d86f4c..042f2c81 100644 --- a/t/snippets/packing_list.txt +++ b/t/snippets/packing_list.txt @@ -572,3 +572,4 @@ ../snippets9.t rt98902.def ../snippets9.t rt98902.rt98902 ../snippets9.t rt99961.def +../snippets30.t logical_xor.def diff --git a/t/snippets30.t b/t/snippets30.t index 35455a9c..1008631c 100644 --- a/t/snippets30.t +++ b/t/snippets30.t @@ -11,6 +11,7 @@ #8 dltc.def #9 dltc.dltc1 #10 dltc.dltc2 +#11 logical_xor.def # To locate test #13 you can search for its name or the string '#13' @@ -84,6 +85,10 @@ $self->make_grammar( [ [ 1950, 150, ], [ 2050, 150, ], ], ] ); +---------- + + 'logical_xor' => <<'----------', +$x^^$y and say "One of x or y is true, but not both"; ---------- }; @@ -229,6 +234,14 @@ $self->make_grammar( ); #10........... }, + + 'logical_xor.def' => { + source => "logical_xor", + params => "def", + expect => <<'#11...........', +$x ^^ $y and say "One of x or y is true, but not both"; +#11........... + }, }; my $ntests = 0 + keys %{$rtests}; -- 2.39.5