Skip to content

Commit

Permalink
Don't allow ranges to span across lines
Browse files Browse the repository at this point in the history
"1..\n2.." was turning into "(1..2).."

This is a backwards-incompatible change because "1..\n2" is also no longer parsed as one range.
  • Loading branch information
oprypin committed Jun 14, 2019
1 parent c68418e commit cc672de
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions spec/compiler/parser/parser_spec.cr
Expand Up @@ -812,6 +812,7 @@ module Crystal
it_parses "(1 ... )", Expressions.new([RangeLiteral.new(1.int32, Nop.new, true)] of ASTNode)
it_parses "foo(1.., 2)", Call.new(nil, "foo", [RangeLiteral.new(1.int32, Nop.new, false), 2.int32] of ASTNode)
it_parses "1..;", RangeLiteral.new(1.int32, Nop.new, false)
it_parses "1..\n2..", Expressions.new([RangeLiteral.new(1.int32, Nop.new, false), RangeLiteral.new(2.int32, Nop.new, false)] of ASTNode)
it_parses "{1.. => 2};", HashLiteral.new([HashLiteral::Entry.new(RangeLiteral.new(1.int32, Nop.new, false), 2.int32)])
it_parses "..2", RangeLiteral.new(Nop.new, 2.int32, false)
it_parses "...2", RangeLiteral.new(Nop.new, 2.int32, true)
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/crystal/syntax/parser.cr
Expand Up @@ -464,13 +464,14 @@ module Crystal

def new_range(exp, location, exclusive)
check_void_value exp, location
next_token_skip_space_or_newline
next_token_skip_space
check_void_expression_keyword
right = if end_token? ||
@token.type == :")" ||
@token.type == :"," ||
@token.type == :";" ||
@token.type == :"=>"
@token.type == :"=>" ||
@token.type == :NEWLINE
Nop.new
else
parse_or
Expand Down

0 comments on commit cc672de

Please sign in to comment.