Skip to content

Commit

Permalink
* ruby33.y: extract {endless_command,endless_arg} rules (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
iliabylich authored Dec 27, 2023
1 parent e309979 commit 7402fcb
Showing 1 changed file with 26 additions and 70 deletions.
96 changes: 26 additions & 70 deletions lib/parser/ruby33.y
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ rule
val[0], val[1], val[2]),
val[3], val[4])
}
| defn_head f_opt_paren_args tEQL command
| defn_head f_opt_paren_args tEQL endless_command
{
def_t, (name_t, ctx) = val[0]
endless_method_name(name_t)
Expand All @@ -273,25 +273,7 @@ rule
@current_arg_stack.pop
@context.in_def = ctx.in_def
}
| defn_head f_opt_paren_args tEQL command kRESCUE_MOD arg
{
def_t, (name_t, ctx) = val[0]
endless_method_name(name_t)

rescue_body = @builder.rescue_body(val[4],
nil, nil, nil,
nil, val[5])

method_body = @builder.begin_body(val[3], [ rescue_body ])

result = @builder.def_endless_method(def_t, name_t,
val[1], val[2], method_body)

local_pop
@current_arg_stack.pop
@context.in_def = ctx.in_def
}
| defs_head f_opt_paren_args tEQL command
| defs_head f_opt_paren_args tEQL endless_command
{
def_t, recv, dot_t, (name_t, ctx) = val[0]
endless_method_name(name_t)
Expand All @@ -303,27 +285,23 @@ rule
@current_arg_stack.pop
@context.in_def = ctx.in_def
}
| defs_head f_opt_paren_args tEQL command kRESCUE_MOD arg
| backref tOP_ASGN command_rhs
{
def_t, recv, dot_t, (name_t, ctx) = val[0]
endless_method_name(name_t)
@builder.op_assign(val[0], val[1], val[2])
}

rescue_body = @builder.rescue_body(val[4],
endless_command: command
| endless_command kRESCUE_MOD arg
{
rescue_body = @builder.rescue_body(val[1],
nil, nil, nil,
nil, val[5])

method_body = @builder.begin_body(val[3], [ rescue_body ])

result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
val[1], val[2], method_body)
nil, val[2])

local_pop
@current_arg_stack.pop
@context.in_def = ctx.in_def
result = @builder.begin_body(val[0], [ rescue_body ])
}
| backref tOP_ASGN command_rhs
| kNOT opt_nl endless_command
{
@builder.op_assign(val[0], val[1], val[2])
result = @builder.not_op(val[0], nil, val[2], nil)
}

command_rhs: command_call =tOP_ASGN
Expand Down Expand Up @@ -939,7 +917,7 @@ rule
result = @builder.ternary(val[0], val[1],
val[2], val[4], val[5])
}
| defn_head f_opt_paren_args tEQL arg
| defn_head f_opt_paren_args tEQL endless_arg
{
def_t, (name_t, ctx) = val[0]
endless_method_name(name_t)
Expand All @@ -951,25 +929,7 @@ rule
@current_arg_stack.pop
@context.in_def = ctx.in_def
}
| defn_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
{
def_t, (name_t, ctx) = val[0]
endless_method_name(name_t)

rescue_body = @builder.rescue_body(val[4],
nil, nil, nil,
nil, val[5])

method_body = @builder.begin_body(val[3], [ rescue_body ])

result = @builder.def_endless_method(def_t, name_t,
val[1], val[2], method_body)

local_pop
@current_arg_stack.pop
@context.in_def = ctx.in_def
}
| defs_head f_opt_paren_args tEQL arg
| defs_head f_opt_paren_args tEQL endless_arg
{
def_t, recv, dot_t, (name_t, ctx) = val[0]
endless_method_name(name_t)
Expand All @@ -981,25 +941,21 @@ rule
@current_arg_stack.pop
@context.in_def = ctx.in_def
}
| defs_head f_opt_paren_args tEQL arg kRESCUE_MOD arg
{
def_t, recv, dot_t, (name_t, ctx) = val[0]
endless_method_name(name_t)
| primary

rescue_body = @builder.rescue_body(val[4],
endless_arg: arg=kRESCUE_MOD
| endless_arg kRESCUE_MOD arg
{
rescue_body = @builder.rescue_body(val[1],
nil, nil, nil,
nil, val[5])

method_body = @builder.begin_body(val[3], [ rescue_body ])

result = @builder.def_endless_singleton(def_t, recv, dot_t, name_t,
val[1], val[2], method_body)
nil, val[2])

local_pop
@current_arg_stack.pop
@context.in_def = ctx.in_def
result = @builder.begin_body(val[0], [ rescue_body ])
}
| kNOT opt_nl endless_arg
{
result = @builder.not_op(val[0], nil, val[2], nil)
}
| primary

relop: tGT | tLT | tGEQ | tLEQ

Expand Down

0 comments on commit 7402fcb

Please sign in to comment.