Skip to content

Commit

Permalink
- lexer.rl: fix paren_nest for curly braces (#646)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich committed Jan 8, 2020
1 parent 384d9a3 commit 96adadc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/parser/lexer.rl
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,6 @@ class Parser::Lexer
emit(:tRCURLY, '}'.freeze, p - 1, p)
@cond.lexpop
@cmdarg.lexpop
@paren_nest -= 1
else
emit(:tSTRING_DEND, '}'.freeze, p - 1, p)
end
Expand All @@ -1079,6 +1078,8 @@ class Parser::Lexer
fbreak;
end
end

@paren_nest -= 1
};

action extend_interp_code {
Expand Down Expand Up @@ -2165,6 +2166,9 @@ class Parser::Lexer
emit_do
end
end
if tok == '{'.freeze
@paren_nest += 1
end
@command_start = true

fnext expr_value; fbreak;
Expand Down
3 changes: 3 additions & 0 deletions test/parse_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@ def try_parsing(ast, code, parser, source_maps, version)

assert parser.instance_eval { @lexer }.cmdarg.empty?,
"(#{version}) expected cmdarg to be empty after parsing"

assert_equal 0, parser.instance_eval { @lexer.instance_eval { @paren_nest } },
"(#{version}) expected paren_nest to be 0 after parsing"
end

# Use like this:
Expand Down
12 changes: 12 additions & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9294,4 +9294,16 @@ def test_pattern_matching_required_parentheses_for_in_match
%{ ^^ location},
SINCE_2_7)
end

def test_parser_bug_645
assert_parses(
s(:block,
s(:lambda),
s(:args,
s(:optarg, :arg,
s(:hash))), nil),
'-> (arg={}) {}',
%{},
SINCE_1_9)
end
end

0 comments on commit 96adadc

Please sign in to comment.