aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parse.y9
-rw-r--r--test/ruby/test_rubyoptions.rb13
2 files changed, 17 insertions, 5 deletions
diff --git a/parse.y b/parse.y
index 88c02082ad..7823b4215d 100644
--- a/parse.y
+++ b/parse.y
@@ -3003,6 +3003,15 @@ k_begin : keyword_begin
k_if : keyword_if
{
token_info_push(p, "if", &@$);
+ if (p->token_info && p->token_info->nonspc &&
+ p->token_info->next && !strcmp(p->token_info->next->token, "if")) {
+ const char *tok = p->lex.ptok, *beg = p->lex.pbeg;
+ while (tok > beg && ISSPACE(*--tok));
+ while (beg < tok && ISSPACE(*beg)) beg++;
+ if (tok - beg == 3 && !memcmp(beg, "else", 4)) {
+ p->token_info->nonspc = 0;
+ }
+ }
}
;
diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb
index 2f78461f2f..d63ca5da4d 100644
--- a/test/ruby/test_rubyoptions.rb
+++ b/test/ruby/test_rubyoptions.rb
@@ -491,14 +491,17 @@ class TestRubyOptions < Test::Unit::TestCase
["begin", "ensure ; end"],
[" case nil", "when true; end"],
["case nil; when true", "end"],
+ ["if false;", "end", "if true\nelse ", "end"],
].each do
- |b, e = 'end'|
- src = ["#{b}\n", " #{e}\n"]
+ |b, e = 'end', pre = nil, post = nil|
+ src = ["#{pre}#{b}\n", " #{e}\n#{post}"]
k = b[/\A\s*(\S+)/, 1]
e = e[/\A\s*(\S+)/, 1]
+ n = 2
+ n += pre.count("\n") if pre
a.for("no directives with #{b}") do
- err = ["#{t.path}:2: warning: mismatched indentations at '#{e}' with '#{k}' at 1"]
+ err = ["#{t.path}:#{n}: warning: mismatched indentations at '#{e}' with '#{k}' at #{n-1}"]
t.rewind
t.truncate(0)
t.puts src
@@ -517,7 +520,7 @@ class TestRubyOptions < Test::Unit::TestCase
end
a.for("false and true directives with #{b}") do
- err = ["#{t.path}:4: warning: mismatched indentations at '#{e}' with '#{k}' at 3"]
+ err = ["#{t.path}:#{n+2}: warning: mismatched indentations at '#{e}' with '#{k}' at #{n+1}"]
t.rewind
t.truncate(0)
t.puts "# -*- warn-indent: false -*-"
@@ -539,7 +542,7 @@ class TestRubyOptions < Test::Unit::TestCase
end
a.for("BOM with #{b}") do
- err = ["#{t.path}:2: warning: mismatched indentations at '#{e}' with '#{k}' at 1"]
+ err = ["#{t.path}:#{n}: warning: mismatched indentations at '#{e}' with '#{k}' at #{n-1}"]
t.rewind
t.truncate(0)
t.print "\u{feff}"