Skip to content

Commit 3fbdde5

Browse files
makenowjustRX14
authored andcommittedSep 7, 2017
Parser: correct to parse 'foo &.%(1)' (#4664)
Fix #4662
1 parent 19bb517 commit 3fbdde5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

Diff for: ‎spec/compiler/parser/parser_spec.cr

+1
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ describe "Parser" do
305305
it_parses "foo(&.block)", Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Var.new("__arg0"), "block")))
306306
it_parses "foo &.block", Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Var.new("__arg0"), "block")))
307307
it_parses "foo &./(1)", Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Var.new("__arg0"), "/", 1.int32)))
308+
it_parses "foo &.%(1)", Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Var.new("__arg0"), "%", 1.int32)))
308309
it_parses "foo &.block(1)", Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Var.new("__arg0"), "block", 1.int32)))
309310
it_parses "foo &.+(2)", Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Var.new("__arg0"), "+", 2.int32)))
310311
it_parses "foo &.bar.baz", Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Call.new(Var.new("__arg0"), "bar"), "baz")))

Diff for: ‎src/compiler/crystal/syntax/parser.cr

+9-1
Original file line numberDiff line numberDiff line change
@@ -1376,8 +1376,16 @@ module Crystal
13761376
@block_arg_count += 1
13771377

13781378
obj = Var.new(block_arg_name)
1379+
13791380
@wants_regex = false
1380-
next_token_skip_space
1381+
if current_char == '%'
1382+
next_char
1383+
@token.type = :"%"
1384+
@token.column_number += 1
1385+
skip_space
1386+
else
1387+
next_token_skip_space
1388+
end
13811389

13821390
location = @token.location
13831391

0 commit comments

Comments
 (0)