[#56329] [ruby-trunk - Bug #8722][Assigned] Refinements remain active beyond the end of an evaled string — "charliesome (Charlie Somerville)" <charliesome@...>

9 messages 2013/08/02

[#56333] [CommonRuby - Feature #8723][Open] Array.any? predicate returns true for empty array. — "nurettin (Nurettin Onur TUGCU)" <onurtugcu@...>

12 messages 2013/08/02

[#56368] [ruby-trunk - Bug #8730][Open] "rescue Exception" rescues Timeout::ExitException — "takiuchi (Genki Takiuchi)" <[email protected]>

15 messages 2013/08/04

[#56407] [ruby-trunk - misc #8741][Open] email notification on bugs.ruby-lang.org is broken — "rits (First Last)" <redmine@...>

18 messages 2013/08/05

[#56524] [ruby-trunk - Bug #8770][Open] [PATCH] process.c: avoid EINTR from Process.spawn — "normalperson (Eric Wong)" <normalperson@...>

19 messages 2013/08/10

[#56536] [ruby-trunk - Feature #8772][Open] Hash alias #| merge, and the case for Hash and Array polymorphism — "trans (Thomas Sawyer)" <redmine@...>

24 messages 2013/08/11

[#56544] [ruby-trunk - Bug #8774][Open] rb_file_dirname return wrong encoding string when dir is "." — jiayp@... (贾 延平) <jiayp@...>

10 messages 2013/08/11

[#56569] [ruby-trunk - Feature #8781][Open] Use require_relative() instead of require() if possible — "ko1 (Koichi Sasada)" <redmine@...>

31 messages 2013/08/12
[#56582] [ruby-trunk - Feature #8781] Use require_relative() instead of require() if possible — "drbrain (Eric Hodel)" <[email protected]> 2013/08/12

[#56584] Re: [ruby-trunk - Feature #8781] Use require_relative() instead of require() if possible — SASADA Koichi <ko1@...> 2013/08/12

(2013/08/13 2:25), drbrain (Eric Hodel) wrote:

[#56636] Re: [ruby-trunk - Feature #8781] Use require_relative() instead of require() if possible — Aaron Patterson <tenderlove@...> 2013/08/16

On Tue, Aug 13, 2013 at 07:38:01AM +0900, SASADA Koichi wrote:

[#56634] [ruby-trunk - Feature #8788][Open] use eventfd on newer Linux instead of pipe for timer thread — "normalperson (Eric Wong)" <normalperson@...>

11 messages 2013/08/16

[#56648] [ruby-trunk - Bug #8795][Open] "Null byte in string error" on Marshal.load — "mml (McClain Looney)" <m@...>

17 messages 2013/08/16

[#56824] [ruby-trunk - Feature #8823][Open] Run trap handler in an independent thread called "Signal thread" — "ko1 (Koichi Sasada)" <redmine@...>

14 messages 2013/08/27

[#56878] [ruby-trunk - misc #8835][Open] Introducing a semantic versioning scheme and branching policy — "knu (Akinori MUSHA)" <knu@...>

11 messages 2013/08/30

[#56890] [ruby-trunk - Feature #8839][Open] Class and module should return the class or module that was opened — "headius (Charles Nutter)" <headius@...>

26 messages 2013/08/30

[#56894] [ruby-trunk - Feature #8840][Open] Yielder#state — "marcandre (Marc-Andre Lafortune)" <ruby-core@...>

14 messages 2013/08/30

[ruby-core:56291] [ruby-trunk - Feature #8714] Non-interpolated regular expression literal

From: "phluid61 (Matthew Kerwin)" <matthew@...>
Date: 2013-08-01 00:24:11 UTC
List: ruby-core #56291
Issue #8714 has been updated by phluid61 (Matthew Kerwin).


Eregon (Benoit Daloze) wrote:
> > Off the top of my head, I can't think of how to construct a regexp literal to match a hash character at the end of the string (i.e. /#$/), without first constructing a string.
> 
> Well you can escape the "#": /\#$/ =~ "#" # => 0.

Of course!

> %r{#$} works too.

  irb(main):004:0> %r{#$}
  SyntaxError: (irb):4: syntax error, unexpected $undefined
  %r{#$}
       ^
  	from /usr/local/bin/irb:12:in `<main>'
  irb(main):005:0> %r{\#$}
  => /\#$/


> If you want to match at the end of the String, you should use /#\z/.

At the end of the line, then.  ;)

> But indeed simply /#$/ gives "unterminated regexp meets end of file".
> After all $/ is a global variable (the input record separator), so it is only logical it interpolates it.

Even if it's not a (valid, defined) global variable, the parser still attempts to interpolate it.  For example: /#$]/  (there is no $] in ruby)

> Also, /regexp/ literal needs escape only for #, \ and / if I am not mistaken,
> which is quite restricted compared to what must be escaped in "" or %Q.

That's only partly true.  # only need be escaped when it is followed by $, @ or {.  Therein lies the source of a lot of confusion.  From what I can see, ruby-doc.org says "Arbitrary Ruby expressions can be embedded into patterns with the #{...} construct." which is very easy to miss, and it's not always clear that "#$x" or /#$x/ are part of the #{...} construct.

I admit that this is a standard part of ruby interpolation, but "#$x#@y" is not commonly encountered in the wild, and is much more likely to occur in a (symbol-rich) regexp than a (typically human readable) string.  Thus I propose an option to construct regexps that don't treat # as special.

Note: I'd still expect other backslash-escapes (like \u{...}) to work in uninterpolated regexps, because even uninterpolated regexps should be able to do normal perly things like %R/\u{263a}\n/
----------------------------------------
Feature #8714: Non-interpolated regular expression literal
https://bugs.ruby-lang.org/issues/8714#change-40782

Author: phluid61 (Matthew Kerwin)
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 


=begin

I propose a new %string for non-interpolated regexp literals: %R

It is common to see erroneous bug reports around the use of ((%#%)) in regexp literals, for example where (({/[$#]/})) raises a syntax error "unexpected $undefined", and this confuses people.  The only solution is to rearrange the regular expression (such as (({/[$#]/}))), which is not always desirable.

An non-interpolated regexp, such as (({%R/[$#]/})), would allow a much simpler resolution.

=== Known Issues

* the capitalisation is the opposite of %Q(interpolated) and %q(uninterpolated)
* %R was also proposed for literal Rationals in #8430, although I believe this has been superseded by the (({1.2r})) syntax

=end



-- 
http://bugs.ruby-lang.org/

In This Thread