Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- lexer.rl: Fix handling of beginless ranges at start of line #822

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions lib/parser/lexer.rl
Expand Up @@ -2513,6 +2513,28 @@ class Parser::Lexer
end
};

c_space* '..'
=> {
emit(:tNL, nil, @newline_s, @newline_s + 1)
if @version < 27
fhold; fnext line_begin; fbreak;
else
emit(:tBDOT2)
fnext expr_beg; fbreak;
end
};

c_space* '...'
=> {
emit(:tNL, nil, @newline_s, @newline_s + 1)
if @version < 27
fhold; fnext line_begin; fbreak;
else
emit(:tBDOT3)
fnext expr_beg; fbreak;
end
};

c_space* %{ tm = p } ('.' | '&.')
=> { p = tm - 1; fgoto expr_end; };

Expand Down
26 changes: 26 additions & 0 deletions test/test_lexer.rb
Expand Up @@ -602,10 +602,36 @@ def test_dot

def test_dot2
assert_scanned "..", :tDOT2, "..", [0, 2]
refute_scanned("foo\n..42",
:tIDENTIFIER, "foo", [0, 3],
:tNL, nil, [3, 4])
end

def test_dot2_27
setup_lexer 27
assert_scanned "..", :tBDOT2, "..", [0, 2]
assert_scanned("foo\n..42",
:tIDENTIFIER, "foo", [0, 3],
:tNL, nil, [3, 4],
:tBDOT2, "..", [4, 6],
:tINTEGER, 42, [6, 8])
end

def test_dot3
assert_scanned "...", :tDOT3, "...", [0, 3]
refute_scanned("foo\n...42",
:tIDENTIFIER, "foo", [0, 3],
:tNL, nil, [3, 4])
end

def test_dot3_27
setup_lexer 27
assert_scanned "...", :tBDOT3, "...", [0, 3]
assert_scanned("foo\n...42",
:tIDENTIFIER, "foo", [0, 3],
:tNL, nil, [3, 4],
:tBDOT3, "...", [4, 7],
:tINTEGER, 42, [7, 9])
end

def test_equals
Expand Down
23 changes: 23 additions & 0 deletions test/test_parser.rb
Expand Up @@ -911,6 +911,29 @@ def test_beginless_range
)
end

def test_beginless_irange_after_newline
assert_parses(
s(:begin,
s(:lvar, :foo),
s(:irange, nil,
s(:int, 100))),
%Q{foo\n..100},
%q{},
SINCE_2_7
)
end

def test_beginless_erange_after_newline
assert_parses(
s(:begin,
s(:lvar, :foo),
s(:erange, nil,
s(:int, 100))),
%Q{foo\n...100},
%q{},
SINCE_2_7
)
end
#
# Access
#
Expand Down