Skip to content

Commit aec0e87

Browse files
committed
Fix some more edge case bugs
1 parent 2f1e261 commit aec0e87

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

lib/opal/parser.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ def new_compstmt(block)
167167
else
168168
block
169169
end
170-
block
171170
end
172171

173172
def new_body(compstmt, res, els, ens)
@@ -258,7 +257,7 @@ def new_not(kw, expr)
258257
end
259258

260259
def new_paren(open, expr, close)
261-
if expr.nil?
260+
if expr.nil? or expr == [:block]
262261
s1(:paren, s0(:nil, source(open)), source(open))
263262
else
264263
s1(:paren, expr, source(open))
@@ -298,7 +297,7 @@ def new_args(norm, opt, rest, block)
298297
end
299298

300299
def new_block_args(norm, opt, rest, block)
301-
res = []
300+
res = s(:array)
302301

303302
if norm
304303
norm.each do |arg|
@@ -331,7 +330,13 @@ def new_block_args(norm, opt, rest, block)
331330

332331
res << opt if opt
333332

334-
res.size == 1 && norm ? res[0] : s(:masgn, s(:array, *res))
333+
args = res.size == 2 && norm ? res[1] : s(:masgn, res)
334+
335+
if args.type == :array
336+
s(:masgn, args)
337+
else
338+
args
339+
end
335340
end
336341

337342
def new_call(recv, meth, args = [])
@@ -516,7 +521,7 @@ def new_super(kw, args)
516521
end
517522

518523
def new_yield(args)
519-
args = (args || s(:arglist))[1..-1]
524+
args ||= []
520525
s(:yield, *args)
521526
end
522527

lib/opal/parser/grammar.rb

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/opal/parser/grammar.y

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ rule
159159
| backref tOP_ASGN command_call
160160
| lhs tEQL mrhs
161161
{
162-
result = new_assign val[0], s(:svalue, val[2])
162+
result = new_assign val[0], val[1], s(:svalue, val[2])
163163
}
164164
| mlhs tEQL arg_value
165165
{
166166
result = s(:masgn, val[0], s(:to_ary, val[2]))
167167
}
168168
| mlhs tEQL mrhs
169169
{
170-
result = s(:masgn, val[0], s(:array, *val[2]))
170+
result = s(:masgn, val[0], val[2])
171171
}
172172
| expr
173173

@@ -210,7 +210,7 @@ rule
210210
{
211211
args = val[1]
212212
args = args[1] if args.size == 2
213-
result = s(:next, args)
213+
result = s(:next, *args)
214214
}
215215

216216
block_command: block_call
@@ -316,12 +316,12 @@ rule
316316
}
317317
| primary_value tLBRACK2 aref_args tRBRACK
318318
{
319-
args = val[2]
319+
args = s(:arglist, *val[2])
320320
result = s(:attrasgn, val[0], :[]=, args)
321321
}
322322
| primary_value tDOT tIDENTIFIER
323323
{
324-
result = new_call val[0], val[2].intern, s(:arglist)
324+
result = new_call val[0], value(val[2]).intern, []
325325
}
326326
| primary_value tCOLON2 tIDENTIFIER
327327
| primary_value tDOT tCONSTANT
@@ -424,7 +424,7 @@ rule
424424
}
425425
| lhs tEQL arg kRESCUE_MOD arg
426426
{
427-
result = new_assign val[0], s(:rescue_mod, val[2], val[4])
427+
result = new_assign val[0], val[1], s(:rescue_mod, val[2], val[4])
428428
}
429429
| var_lhs tOP_ASGN arg
430430
{
@@ -589,7 +589,7 @@ rule
589589
}
590590
| command opt_nl
591591
{
592-
result = s(:array, val[0])
592+
result = [val[0]]
593593
}
594594
| args trailer
595595
{
@@ -602,7 +602,7 @@ rule
602602
}
603603
| assocs trailer
604604
{
605-
result = s(:array, s(:hash, *val[0]))
605+
result = [s(:hash, *val[0])]
606606
}
607607

608608
paren_args: tLPAREN2 none tRPAREN
@@ -703,7 +703,7 @@ rule
703703
mrhs: args tCOMMA arg_value
704704
{
705705
val[0] << val[2]
706-
result = val[0]
706+
result = s(:array, *val[0])
707707
}
708708
| args tCOMMA tSTAR arg_value
709709
| tSTAR arg_value
@@ -1154,7 +1154,7 @@ opt_block_args_tail: tCOMMA block_args_tail
11541154
opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
11551155
{
11561156
exc = val[1] || s(:array)
1157-
exc << new_assign(val[2], s(:gvar, '$!'.intern)) if val[2]
1157+
exc << new_assign(val[2], val[2], s(:gvar, '$!'.intern)) if val[2]
11581158
result = [s(:resbody, exc, val[4])]
11591159
result.push val[5].first if val[5]
11601160
}

lib/opal/parser/lexer.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ def yylex
595595

596596
if scan(/\=end/) and space?
597597
@line += line_count
598-
return next_token
598+
return yylex
599599
end
600600

601601
if scan(/\n/)
@@ -1047,7 +1047,7 @@ def yylex
10471047
else # we were probably parsing a heredoc, so pop that parser and continue
10481048
@scanner_stack.pop
10491049
@scanner = @scanner_stack.last
1050-
return next_token
1050+
return yylex
10511051
end
10521052
end
10531053

0 commit comments

Comments
 (0)