[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#6286: General delimited literals in ruby-mode patch
From: |
Dmitry Gutov |
Subject: |
bug#6286: General delimited literals in ruby-mode patch |
Date: |
Wed, 25 Apr 2012 07:03:05 +0400 |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 |
So, the patch.
On 24.04.2012 21:09, Stefan Monnier wrote:
Here is what it does:
- Split large regexp into more manageable chunks.
I didn't think to use match groups this way. Very nice.
- During the split I saw that gsub/sub/split/scan were matched (for
regexp) without regards to what precedes them, so "asub / a + bsub / b"
was taken for a regexp.
This fix has uncovered another problem: "gsub", "gsub!", "sub", "sub!",
"scan", "split", and "split!" are not special tokens, those are all
methods on class String: http://www.ruby-doc.org/core-1.9.3/String.html
The original author just collected the methods most often used with
regexps. And now this is broken: "abcdec".split /[be]/
One might argue that this isn't the most important use case, and that
methods with arity > 1 are covered by the second rule (comma after), but
5 of these 7 methods can be called with just 1 argument. So that would
mean backward incompatibility.
- I found a problem in your approach to handling Cucumber code.
I'm assuming you mean this:
x = toto / foo if /do bar/ =~ "dobar" # shortened version
We can add a constraint that "do" is followed by (optionally) |a, d, c|
(block arguments), and then EOL, since do ... end syntax isn't usually
used with one-liner blocks, especially not after a regexp argument.
Or we can revert the change and do it the original way.
I looked into how other editors deal with regular expressions in Ruby.
Vim is whitespace-sensitive. In the example above, the highlighting
depends on whether you put space before "foo" (so it highlights one or
the other regexp-looking expression).
Textmate favors the whitelisting approach, like ruby-mode had pre-patch:
http://www.ruby-forum.com/topic/170852
It has one benefit in that when you've typed the regexp, it's already
highlighted, before you type the block keyword. Might feel more natural.
In this approach, we'd move the "hardcoded" list of special method names
to a variable, so that users might customize it, per project.
What do you think?
And here's a patch for another issue (attached).
-- Dmitry
0001-ruby-mode-Don-t-propertize-percent-literals-inside-s.patch
Description: Text document