Skip to content

Commit

Permalink
Parser: fixed #4608, correct to parse regex after close bracket
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust authored and asterite committed Aug 20, 2017
1 parent e811cf9 commit 32d7e3e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Expand Up @@ -108,6 +108,9 @@ describe "Parser" do
it_parses "@foo/2", Call.new("@foo".instance_var, "/", 2.int32)
it_parses "@@foo/2", Call.new("@@foo".class_var, "/", 2.int32)
it_parses "1+2*3", Call.new(1.int32, "+", Call.new(2.int32, "*", 3.int32))
it_parses "foo[] /2", Call.new(Call.new("foo".call, "[]"), "/", 2.int32)
it_parses "foo[1] /2", Call.new(Call.new("foo".call, "[]", 1.int32), "/", 2.int32)
it_parses "[1] /2", Call.new(([1.int32] of ASTNode).array, "/", 2.int32)

it_parses "!1", Not.new(1.int32)
it_parses "- 1", Call.new(1.int32, "-")
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/crystal/syntax/parser.cr
Expand Up @@ -692,6 +692,7 @@ module Crystal
check_void_value atomic, location

column_number = @token.column_number
@wants_regex = false
next_token_skip_space
atomic = Call.new(atomic, "[]", name_column_number: column_number).at(location)
atomic.name_size = 0 if atomic.is_a?(Call)
Expand All @@ -704,6 +705,7 @@ module Crystal
call_args = preserve_stop_on_do { parse_call_args_space_consumed check_plus_and_minus: false, allow_curly: true, end_token: :"]" }
skip_space_or_newline
check :"]"
@wants_regex = false
next_token

if call_args
Expand Down Expand Up @@ -1199,6 +1201,7 @@ module Crystal
end
end
check :"]"
@wants_regex = false
next_token_skip_space

attr = Attribute.new(name, args, named_args)
Expand Down Expand Up @@ -2071,6 +2074,7 @@ module Crystal
break
end
end
@wants_regex = false
next_token_skip_space
end

Expand Down Expand Up @@ -4494,6 +4498,7 @@ module Crystal
next_token_skip_space
size = parse_single_type allow_primitives: true
check :"]"
@wants_regex = false
next_token_skip_space
type = make_static_array_type(type, size).at(type.location)
when :"."
Expand Down

0 comments on commit 32d7e3e

Please sign in to comment.