Skip to content

Commit 32d7e3e

Browse files
makenowjustasterite
authored andcommittedAug 20, 2017
Parser: fixed #4608, correct to parse regex after close bracket
1 parent e811cf9 commit 32d7e3e

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed
 

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

+3
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ describe "Parser" do
108108
it_parses "@foo/2", Call.new("@foo".instance_var, "/", 2.int32)
109109
it_parses "@@foo/2", Call.new("@@foo".class_var, "/", 2.int32)
110110
it_parses "1+2*3", Call.new(1.int32, "+", Call.new(2.int32, "*", 3.int32))
111+
it_parses "foo[] /2", Call.new(Call.new("foo".call, "[]"), "/", 2.int32)
112+
it_parses "foo[1] /2", Call.new(Call.new("foo".call, "[]", 1.int32), "/", 2.int32)
113+
it_parses "[1] /2", Call.new(([1.int32] of ASTNode).array, "/", 2.int32)
111114

112115
it_parses "!1", Not.new(1.int32)
113116
it_parses "- 1", Call.new(1.int32, "-")

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

+5
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,7 @@ module Crystal
692692
check_void_value atomic, location
693693

694694
column_number = @token.column_number
695+
@wants_regex = false
695696
next_token_skip_space
696697
atomic = Call.new(atomic, "[]", name_column_number: column_number).at(location)
697698
atomic.name_size = 0 if atomic.is_a?(Call)
@@ -704,6 +705,7 @@ module Crystal
704705
call_args = preserve_stop_on_do { parse_call_args_space_consumed check_plus_and_minus: false, allow_curly: true, end_token: :"]" }
705706
skip_space_or_newline
706707
check :"]"
708+
@wants_regex = false
707709
next_token
708710

709711
if call_args
@@ -1199,6 +1201,7 @@ module Crystal
11991201
end
12001202
end
12011203
check :"]"
1204+
@wants_regex = false
12021205
next_token_skip_space
12031206

12041207
attr = Attribute.new(name, args, named_args)
@@ -2071,6 +2074,7 @@ module Crystal
20712074
break
20722075
end
20732076
end
2077+
@wants_regex = false
20742078
next_token_skip_space
20752079
end
20762080

@@ -4494,6 +4498,7 @@ module Crystal
44944498
next_token_skip_space
44954499
size = parse_single_type allow_primitives: true
44964500
check :"]"
4501+
@wants_regex = false
44974502
next_token_skip_space
44984503
type = make_static_array_type(type, size).at(type.location)
44994504
when :"."

0 commit comments

Comments
 (0)
Please sign in to comment.