Project

General

Profile

Feature #12700

regexg heredoc support

Added by gam3 (Allen Morris) almost 4 years ago. Updated over 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:77035]

Description

There is support for ', ", and ` heredocs, but there is no support for /.

Example code with new feature:

first = 'first'

orig = /#{first}
match\s # match
this    # match this
/x

right = <</REGEXP/x
#{first}
match\s # match
this    # match this
REGEXP

raise unless orig == right

There is no straight forward way to replace a regexp heredoc as a double quote heredoc requires that '\s' be escaped.
As shown in the code below you can't use the string heredoc to directly replace a regexp heredoc because of this need for extra escaping.

first = 'first'

orig = /#{first}
match\s # match
this    # match this
/x

wrong = Regexp.new(<<REGEXP, Regexp::EXTENDED)
#{first}
match\s # match
this    # match this
REGEXP

right = Regexp.new(<<REGEXP, Regexp::EXTENDED)
#{first}
match\\s # match
this    # match this
REGEXP

raise unless orig != wrong
raise unless orig == right

Files

regex_heredoc_patch (2.99 KB) regex_heredoc_patch patch to enable regex heredoc gam3 (Allen Morris), 08/24/2016 08:39 AM

Also available in: Atom PDF