Skip to content

Commit

Permalink
- lexer.rl: emit tMETHREF as tDOT+tCOLON for rubies < 27. (#614)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich authored Sep 19, 2019
1 parent c1295b0 commit d2444ae
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
14 changes: 13 additions & 1 deletion lib/parser/lexer.rl
Original file line number Diff line number Diff line change
Expand Up @@ -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; };

Expand Down
4 changes: 4 additions & 0 deletions test/test_lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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],
Expand Down
16 changes: 15 additions & 1 deletion test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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' }],
Expand Down

0 comments on commit d2444ae

Please sign in to comment.