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

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

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

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

trosel opened this issue Nov 14, 2017 · 7 comments
Labels
docs Documentation issue (primary issue type)

Comments

@trosel
Copy link
Contributor

trosel commented Nov 14, 2017

hankache/rakuguide#135

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

@raiph
Copy link
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
Copy link
Member

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
Copy link
Contributor Author

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
Copy link
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
Copy link
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 Documentation issue (primary issue type) label Jan 17, 2018
@zoffixznet
Copy link
Contributor

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

Also in Bool context.

@tisonkun
Copy link
Member

tisonkun commented May 4, 2018

Close this via 6dec94a
https://docs.perl6.org/language/regexes#Lexical_Conventions

@tisonkun tisonkun closed this as completed 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
Labels
docs Documentation issue (primary issue type)
Projects
None yet
Development

No branches or pull requests

7 participants