diff --git a/lib/parser/lexer.rl b/lib/parser/lexer.rl index 7d4d07518..36ee32a21 100644 --- a/lib/parser/lexer.rl +++ b/lib/parser/lexer.rl @@ -1357,21 +1357,21 @@ class Parser::Lexer w_space* '?' => { fhold; fgoto expr_beg; }; - # a %{1}, a %[1] (but not "a %=1=" or "a % foo") - # a /foo/ (but not "a / foo" or "a /=foo") - w_space+ ( [%/] ( c_any - c_space_nl - '=' ) # / - # a < { fhold; fhold; fgoto expr_beg; }; - - # x /1 - # Ambiguous regexp literal. - w_space+ '/' + # a %{1}, a %[1] (but not "a %=1=" or "a % foo") + # a /foo/ (but not "a / foo" or "a /=foo") + # a < { - diagnostic :warning, :ambiguous_literal, nil, range(@te - 1, @te) + if tok(tm, tm + 1) == '/' + # Ambiguous regexp literal. + diagnostic :warning, :ambiguous_literal, nil, range(tm, tm + 1) + end - fhold; fgoto expr_beg; + p = tm - 1 + fgoto expr_beg; }; # x *1 diff --git a/test/parse_helper.rb b/test/parse_helper.rb index 0f89e0319..7d130fc4b 100644 --- a/test/parse_helper.rb +++ b/test/parse_helper.rb @@ -161,6 +161,23 @@ def assert_diagnoses(diagnostic, code, source_maps='', versions=ALL_VERSIONS) end end + def refute_diagnoses(code, versions=ALL_VERSIONS) + with_versions(versions) do |version, parser| + source_file = Parser::Source::Buffer.new('(refute_diagnoses)') + source_file.source = code + + begin + parser = parser.parse(source_file) + rescue Parser::SyntaxError + # do nothing; the diagnostic was reported + end + + assert_empty @diagnostics, + "(#{version}) emits no diagnostics, not\n" \ + "#{@diagnostics.map(&:render).join("\n")}" + end + end + SOURCE_MAP_DESCRIPTION_RE = /(?x) ^(?# $1 skip) ^(\s*) diff --git a/test/test_parser.rb b/test/test_parser.rb index 9e30d615f..158000cc8 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -2578,6 +2578,16 @@ def test_send_plain_cmd |~~~~~~~~~~~~ expression}) end + def test_send_plain_cmd_ambiguous_literal + assert_diagnoses( + [:warning, :ambiguous_literal], + %q{m /foo/}, + %q{ ^ location}) + + refute_diagnoses( + %q{m %[1]}) + end + def test_send_plain_cmd_ambiguous_prefix assert_diagnoses( [:warning, :ambiguous_prefix, { :prefix => '+' }],