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

Difference between //, m//, and rx// in regex #1675

Closed
trosel opened this Issue Nov 14, 2017 · 7 comments

Comments

Projects
None yet
7 participants
@trosel
Contributor

trosel commented Nov 14, 2017

hankache/perl6intro#135

What might be a good/quick way to explain the differences in the intro guide?

@raiph

This comment has been minimized.

Show comment
Hide comment
@raiph

raiph Nov 15, 2017

Contributor
  • / ... / declares a regex. If it's used in sink context or on the right of ~~ it is also run.

  • rx/ ... / is the same as / ... / except that rx can use alternative delimiters, eg. rx { ... }.

  • m/ ... / is the same as rx/ ... / except that it is always immediately run.

Contributor

raiph commented Nov 15, 2017

  • / ... / declares a regex. If it's used in sink context or on the right of ~~ it is also run.

  • rx/ ... / is the same as / ... / except that rx can use alternative delimiters, eg. rx { ... }.

  • m/ ... / is the same as rx/ ... / except that it is always immediately run.

@TisonKun

This comment has been minimized.

Show comment
Hide comment
@TisonKun

TisonKun Nov 15, 2017

Contributor

FWIW, users may be curious about why m:g works but rx:g doesn't. We can point it out explicitly.

[12:55] <raiph> wander: yes. some adverbs apply *inside* the *declarations* of regexes, others apply to *matches* see https://docs.perl6.org/language/regexes#Matching_adverbs
[12:58] <wander> how about the difference between 'rx:g' and 'm:g'
[13:03] <raiph> m is a match operation that can take match adverbs; it just happens to include a regex declaration in its syntax
[13:04] <raiph> rx is a regex declaration that can't take match adverbs; it just happens to sometimes be immediately run if in sink context or rhs of ~~

https://github.com/rakudo/rakudo/blob/fff43fd709cd0ed9693a85d06242f0fcd9f55ba3/src/Perl6/Grammar.nqp#L3814-L3833

https://github.com/rakudo/rakudo/blob/fff43fd709cd0ed9693a85d06242f0fcd9f55ba3/src/Perl6/Actions.nqp#L8056-L8088

Contributor

TisonKun commented Nov 15, 2017

FWIW, users may be curious about why m:g works but rx:g doesn't. We can point it out explicitly.

[12:55] <raiph> wander: yes. some adverbs apply *inside* the *declarations* of regexes, others apply to *matches* see https://docs.perl6.org/language/regexes#Matching_adverbs
[12:58] <wander> how about the difference between 'rx:g' and 'm:g'
[13:03] <raiph> m is a match operation that can take match adverbs; it just happens to include a regex declaration in its syntax
[13:04] <raiph> rx is a regex declaration that can't take match adverbs; it just happens to sometimes be immediately run if in sink context or rhs of ~~

https://github.com/rakudo/rakudo/blob/fff43fd709cd0ed9693a85d06242f0fcd9f55ba3/src/Perl6/Grammar.nqp#L3814-L3833

https://github.com/rakudo/rakudo/blob/fff43fd709cd0ed9693a85d06242f0fcd9f55ba3/src/Perl6/Actions.nqp#L8056-L8088

@trosel

This comment has been minimized.

Show comment
Hide comment
@trosel

trosel Nov 15, 2017

Contributor

@raiph is your explanation in the docs? I couldn't find it by searching m// or rx//

I think I must have found it previously in a regex guide separate from the search bar.

Contributor

trosel commented Nov 15, 2017

@raiph is your explanation in the docs? I couldn't find it by searching m// or rx//

I think I must have found it previously in a regex guide separate from the search bar.

@raiph

This comment has been minimized.

Show comment
Hide comment
@raiph

raiph Nov 15, 2017

Contributor

@WildYorkies Searching for rx leads to the general language/regex page which explains this stuff starting at the section Adverbs.

Edited to add...

Er, I thought you were asking about the adverb explanation.

If you mean my three bullet point summary, that's just my own best effort at an accurate and comprehensive explanation, hopefully brief and simple enough for the intro, but maybe not, explaining the differences between the three constructs listed in this issue's title. I think that what I've written is implicit in a careful reading of the longer more scattered explanations in the doc but ymmv.

Contributor

raiph commented Nov 15, 2017

@WildYorkies Searching for rx leads to the general language/regex page which explains this stuff starting at the section Adverbs.

Edited to add...

Er, I thought you were asking about the adverb explanation.

If you mean my three bullet point summary, that's just my own best effort at an accurate and comprehensive explanation, hopefully brief and simple enough for the intro, but maybe not, explaining the differences between the three constructs listed in this issue's title. I think that what I've written is implicit in a careful reading of the longer more scattered explanations in the doc but ymmv.

@AlexDaniel

This comment has been minimized.

Show comment
Hide comment
@AlexDaniel

AlexDaniel Nov 16, 2017

Member

I'm a bit late to the party, but FWIW here are some tickets:

  • RT#130363 [open]: [@LARRY] there's no match for Any aka /./ codegens differently from m/./
  • RT#131925 [open]: [BUG] [REGEX] Smartmatch against `m//` operator mishandles junctions
Member

AlexDaniel commented Nov 16, 2017

I'm a bit late to the party, but FWIW here are some tickets:

  • RT#130363 [open]: [@LARRY] there's no match for Any aka /./ codegens differently from m/./
  • RT#131925 [open]: [BUG] [REGEX] Smartmatch against `m//` operator mishandles junctions

@coke coke added the docs label Jan 17, 2018

@zoffixznet

This comment has been minimized.

Show comment
Hide comment
@zoffixznet

zoffixznet Feb 7, 2018

Member

/ ... / declares a regex. If it's used in sink context or on the right of ~~ it is also run.

Also in Bool context.

Member

zoffixznet commented Feb 7, 2018

/ ... / declares a regex. If it's used in sink context or on the right of ~~ it is also run.

Also in Bool context.

@TisonKun

This comment has been minimized.

Show comment
Hide comment
Contributor

TisonKun commented May 4, 2018

@TisonKun TisonKun closed this May 4, 2018

@JJ JJ added this to the May SQUASHathon milestone May 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment