Skip to content

Commit

Permalink
Fix some more edge case bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Nov 22, 2013
1 parent 2f1e261 commit aec0e87
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 27 deletions.
15 changes: 10 additions & 5 deletions lib/opal/parser.rb
Expand Up @@ -167,7 +167,6 @@ def new_compstmt(block)
else
block
end
block
end

def new_body(compstmt, res, els, ens)
Expand Down Expand Up @@ -258,7 +257,7 @@ def new_not(kw, expr)
end

def new_paren(open, expr, close)
if expr.nil?
if expr.nil? or expr == [:block]
s1(:paren, s0(:nil, source(open)), source(open))
else
s1(:paren, expr, source(open))
Expand Down Expand Up @@ -298,7 +297,7 @@ def new_args(norm, opt, rest, block)
end

def new_block_args(norm, opt, rest, block)
res = []
res = s(:array)

if norm
norm.each do |arg|
Expand Down Expand Up @@ -331,7 +330,13 @@ def new_block_args(norm, opt, rest, block)

res << opt if opt

res.size == 1 && norm ? res[0] : s(:masgn, s(:array, *res))
args = res.size == 2 && norm ? res[1] : s(:masgn, res)

if args.type == :array
s(:masgn, args)
else
args
end
end

def new_call(recv, meth, args = [])
Expand Down Expand Up @@ -516,7 +521,7 @@ def new_super(kw, args)
end

def new_yield(args)
args = (args || s(:arglist))[1..-1]
args ||= []
s(:yield, *args)
end

Expand Down
20 changes: 10 additions & 10 deletions lib/opal/parser/grammar.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions lib/opal/parser/grammar.y
Expand Up @@ -159,15 +159,15 @@ rule
| backref tOP_ASGN command_call
| lhs tEQL mrhs
{
result = new_assign val[0], s(:svalue, val[2])
result = new_assign val[0], val[1], s(:svalue, val[2])
}
| mlhs tEQL arg_value
{
result = s(:masgn, val[0], s(:to_ary, val[2]))
}
| mlhs tEQL mrhs
{
result = s(:masgn, val[0], s(:array, *val[2]))
result = s(:masgn, val[0], val[2])
}
| expr

Expand Down Expand Up @@ -210,7 +210,7 @@ rule
{
args = val[1]
args = args[1] if args.size == 2
result = s(:next, args)
result = s(:next, *args)
}

block_command: block_call
Expand Down Expand Up @@ -316,12 +316,12 @@ rule
}
| primary_value tLBRACK2 aref_args tRBRACK
{
args = val[2]
args = s(:arglist, *val[2])
result = s(:attrasgn, val[0], :[]=, args)
}
| primary_value tDOT tIDENTIFIER
{
result = new_call val[0], val[2].intern, s(:arglist)
result = new_call val[0], value(val[2]).intern, []
}
| primary_value tCOLON2 tIDENTIFIER
| primary_value tDOT tCONSTANT
Expand Down Expand Up @@ -424,7 +424,7 @@ rule
}
| lhs tEQL arg kRESCUE_MOD arg
{
result = new_assign val[0], s(:rescue_mod, val[2], val[4])
result = new_assign val[0], val[1], s(:rescue_mod, val[2], val[4])
}
| var_lhs tOP_ASGN arg
{
Expand Down Expand Up @@ -589,7 +589,7 @@ rule
}
| command opt_nl
{
result = s(:array, val[0])
result = [val[0]]
}
| args trailer
{
Expand All @@ -602,7 +602,7 @@ rule
}
| assocs trailer
{
result = s(:array, s(:hash, *val[0]))
result = [s(:hash, *val[0])]
}

paren_args: tLPAREN2 none tRPAREN
Expand Down Expand Up @@ -703,7 +703,7 @@ rule
mrhs: args tCOMMA arg_value
{
val[0] << val[2]
result = val[0]
result = s(:array, *val[0])
}
| args tCOMMA tSTAR arg_value
| tSTAR arg_value
Expand Down Expand Up @@ -1154,7 +1154,7 @@ opt_block_args_tail: tCOMMA block_args_tail
opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
{
exc = val[1] || s(:array)
exc << new_assign(val[2], s(:gvar, '$!'.intern)) if val[2]
exc << new_assign(val[2], val[2], s(:gvar, '$!'.intern)) if val[2]
result = [s(:resbody, exc, val[4])]
result.push val[5].first if val[5]
}
Expand Down
4 changes: 2 additions & 2 deletions lib/opal/parser/lexer.rb
Expand Up @@ -595,7 +595,7 @@ def yylex

if scan(/\=end/) and space?
@line += line_count
return next_token
return yylex
end

if scan(/\n/)
Expand Down Expand Up @@ -1047,7 +1047,7 @@ def yylex
else # we were probably parsing a heredoc, so pop that parser and continue
@scanner_stack.pop
@scanner = @scanner_stack.last
return next_token
return yylex
end
end

Expand Down

0 comments on commit aec0e87

Please sign in to comment.