xsawyerx / guacamole

Guacamole is a parser toolkit for Standard Perl. It provides fully static BNF-based parsing capability to a reasonable subset of Perl.
https://metacpan.org/pod/Guacamole
20 stars 8 forks source link

Alternate regexp delimiters trigger a warning #89

Closed scottchiefbaker closed 4 years ago

scottchiefbaker commented 4 years ago

Consider the following code to remove https:// from a string

my $str = "https://google.com";

# Triggers a warning (but is must more readable)
$str =~ s|https://||;

# No warning, but a lot harder to read
$str =~ s/https:\/\///;

I think alternate regexp delimiters should be considered standard. At least some primary chars like: |, /, !', and maybe@` should be OK.

rabbiveesh commented 4 years ago

If you're making a list of quote delimiters, {} should be supported too.

On Mon, Jun 29, 2020, 03:34 Scott Baker notifications@github.com wrote:

Consider the following code to remove https:// from a string

my $str = "https://google.com";

Triggers a warning (but is must more readable)

$str =~ s|https://||;

No warning, but a lot harder to read

$str =~ s/https:\/\///;

I think alternate regexp delimiters should be considered standard. At least some primary chars like: |, /, !', and maybe @` should be OK.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/xsawyerx/guacamole/issues/89, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFURPKWVKTLZETW6WSF2RADRY7ORTANCNFSM4OKY75RA .

xsawyerx commented 4 years ago

s can use the following additional delimiters:

Pipe is possible but I'm not a fan because it's a fairly distance character for non-Perl devs who aren't used to other Perl devs using it. (I never used it personally.) Will s!!! not work?

scottchiefbaker commented 4 years ago

I dunno why but I've always used | as an alternate delimiter. it's not a huge deal breaker though. I can switch to !.

Not really clear what this means:

I'm not a fan because it's a fairly distance character for non-Perl devs who aren't used to other Perl devs using it

jeffreykegler commented 4 years ago

FWIW I favor being extremely liberal in delimiters. |, for example, is visually quite distinct, and can have the right 'look' in some cases. Of course, if the strings to be delimited contain ! but not | , then | is a superior choice. And I can imagine some application which has painted itself into a corner where the only character that is not in a delimited string is '3' is, in which case the digit 3 is the ideal delimiter. I personally like to have any printable character available as a delimiter, just in case.

scottchiefbaker commented 4 years ago

I took an informal poll on #perl and | was a popular delimiter. I'm fine if we want to exclude it, but bear in mind it's used in a lot of "real" code.

gonzus commented 4 years ago

I think the point here is to restrict this and get back some sanity. I remember seeing code that used \0 as delimiters... which is great for war stories, but is totally bonkers. I am personally also against # because I want my brain to think "comment" when I see a #.

FWIW, I personally like using | as a delimiter. But I will go along with any restricted list that excludes crazy shit.

xsawyerx commented 4 years ago

I dunno why but I've always used | as an alternate delimiter. it's not a huge deal breaker though. I can switch to !.

Not really clear what this means:

I'm not a fan because it's a fairly distance character for non-Perl devs who aren't used to other Perl devs using it

Sorry, this is my poor phrasing.

I meant that, if you're not a Perl developer who saw a different Perl developer use the pipe operator as a delimiter, you wouldn't even think about using it. Of course, this is a presumption on my part.

I'm okay adding the pipe symbol as a delimiter. I'll try to add it this week. (I want to add a bunch of docs and merge other stuff too for a release this weekend.)

scottchiefbaker commented 4 years ago

Sounds good. Thank you for being flexible on this issue.

xsawyerx commented 4 years ago

Honestly, no reason here for me to be stubborn. The pipe symbol still gives us all we want. Also, I'm not likely to argue a point that is in opposition to both @gonzus and @jeffreykegler. :)

xsawyerx commented 4 years ago

PR now available.

xsawyerx commented 4 years ago

This is now available in 0.005, on CPAN: https://metacpan.org/pod/standard.

scottchiefbaker commented 4 years ago

This is issue is resolved after testing with 0.005.