From d2444aef18cc1da719fbe2592f22612702b76815 Mon Sep 17 00:00:00 2001 From: Ilya Bylich Date: Thu, 19 Sep 2019 13:11:59 +0200 Subject: [PATCH] - lexer.rl: emit tMETHREF as tDOT+tCOLON for rubies < 27. (#614) --- lib/parser/lexer.rl | 14 +++++++++++++- test/test_lexer.rb | 4 ++++ test/test_parser.rb | 16 +++++++++++++++- 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/lib/parser/lexer.rl b/lib/parser/lexer.rl index 9ba2d6a3a..387d30691 100644 --- a/lib/parser/lexer.rl +++ b/lib/parser/lexer.rl @@ -2339,7 +2339,19 @@ class Parser::Lexer p = p - tok.length + 2 fnext expr_dot; fbreak; }; - '.:' | '.' | '&.' | '::' + '.:' + => { + if @version >= 27 + emit_table(PUNCTUATION) + else + emit(:tDOT, tok(@ts, @ts + 1), @ts, @ts + 1) + fhold; + end + + fnext expr_dot; fbreak; + }; + + '.' | '&.' | '::' => { emit_table(PUNCTUATION) fnext expr_dot; fbreak; }; diff --git a/test/test_lexer.rb b/test/test_lexer.rb index 3f9f41f6b..78c0cca78 100644 --- a/test/test_lexer.rb +++ b/test/test_lexer.rb @@ -3559,6 +3559,8 @@ def test_ambiguous_integer_re end def test_meth_ref + setup_lexer(27) + assert_scanned('foo.:bar', :tIDENTIFIER, 'foo', [0, 3], :tMETHREF, '.:', [3, 5], @@ -3571,6 +3573,8 @@ def test_meth_ref end def test_meth_ref_unary_op + setup_lexer(27) + assert_scanned('foo.:+', :tIDENTIFIER, 'foo', [0, 3], :tMETHREF, '.:', [3, 5], diff --git a/test/test_parser.rb b/test/test_parser.rb index 72a945f92..f1354cc7a 100644 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -7214,7 +7214,7 @@ def test_parser_slash_slash_n_escaping_in_literals end end - def test_meth_ref + def test_meth_ref__27 assert_parses( s(:meth_ref, s(:lvar, :foo), :bar), %q{foo.:bar}, @@ -7232,6 +7232,20 @@ def test_meth_ref SINCE_2_7) end + def test_meth_ref__before_27 + assert_diagnoses( + [:error, :unexpected_token, { :token => 'tCOLON' }], + %q{foo.:bar}, + %q{ ^ location }, + ALL_VERSIONS - SINCE_2_7) + + assert_diagnoses( + [:error, :unexpected_token, { :token => 'tCOLON' }], + %q{foo.:+@}, + %q{ ^ location }, + ALL_VERSIONS - SINCE_2_7) + end + def test_meth_ref_unsupported_newlines assert_diagnoses( [:error, :unexpected_token, { :token => 'tCOLON' }],