lib/ruby19_parser.y in ruby_parser-3.0.0.a8 vs lib/ruby19_parser.y in ruby_parser-3.0.0.a9
- old
+ new
@@ -237,11 +237,11 @@
command_call: command
| block_command
block_command: block_call
- | block_call tDOT operation2 command_args
+ | block_call tDOT operation2 command_args # TODO: dot_or_colon
{
result = new_call val[0], val[2], val[3]
}
| block_call tCOLON2 operation2 command_args
{
@@ -269,39 +269,43 @@
}
| operation command_args cmd_brace_block
{
result = new_call nil, val[0].to_sym, val[1]
if val[2] then
- if result[0] == :block_pass then
- raise "both block arg and actual block given"
- end
+ block_dup_check result, val[2]
+
result, operation = val[2], result
result.insert 1, operation
end
}
| primary_value tDOT operation2 command_args =tLOWEST
{
result = new_call val[0], val[2].to_sym, val[3]
}
| primary_value tDOT operation2 command_args cmd_brace_block
{
- result = new_call val[0], val[2].to_sym, val[3]
+ recv, _, msg, args, block = val
+ call = new_call recv, msg.to_sym, args
+
+ block_dup_check call, block
+
+ block.insert 1, call
+ result = block
}
| primary_value tCOLON2 operation2 command_args =tLOWEST
{
result = new_call val[0], val[2].to_sym, val[3]
}
| primary_value tCOLON2 operation2 command_args cmd_brace_block
{
- result = new_call val[0], val[2].to_sym, val[3]
- if val[4] then
- if result[0] == :block_pass then # REFACTOR
- raise "both block arg and actual block given"
- end
- val[2] << result
- result = val[2]
- end
+ recv, _, msg, args, block = val
+ call = new_call recv, msg.to_sym, args
+
+ block_dup_check call, block
+
+ block.insert 1, call
+ result = block
}
| kSUPER command_args
{
result = new_super val[1]
}
@@ -836,11 +840,11 @@
result = self.arg_blk_pass result, val[3]
}
| block_arg
command_args: {
- result = lexer.cmdarg.stack.dup
+ result = lexer.cmdarg.stack.dup # TODO: smell?
lexer.cmdarg.push true
}
call_args
{
lexer.cmdarg.stack.replace val[0]
@@ -968,11 +972,11 @@
{
result = s(:call, val[2], :"!")
}
| kNOT tLPAREN2 rparen
{
- raise "no3: #{val.inspect}"
+ raise "no3\non#{val.inspect}"
}
| operation brace_block
{
oper, iter = val[0], val[1]
call = new_call nil, oper.to_sym
@@ -982,11 +986,12 @@
}
| method_call
| method_call brace_block
{
call, iter = val[0], val[1]
- iter.insert 1, call
+ block_dup_check call, iter
+ iter.insert 1, call # FIX
result = iter
}
| tLAMBDA lambda
{
result = val[1]
@@ -1210,39 +1215,39 @@
{
result = block_var val[0], nil, nil
}
| f_marg_list tCOMMA tSTAR f_norm_arg
{
- raise "no9: #{val.inspect}"
+ result = block_var val[0], val[3], nil
}
| f_marg_list tCOMMA tSTAR f_norm_arg tCOMMA f_marg_list
{
- raise "no10: #{val.inspect}"
+ raise "no10\non: #{val.inspect}"
}
| f_marg_list tCOMMA tSTAR
{
- raise "no11: #{val.inspect}"
+ raise "no11\non: #{val.inspect}"
}
| f_marg_list tCOMMA tSTAR tCOMMA f_marg_list
{
- raise "no12: #{val.inspect}"
+ raise "no12\non: #{val.inspect}"
}
| tSTAR f_norm_arg
{
- raise "no13: #{val.inspect}"
+ raise "no13\non: #{val.inspect}"
}
| tSTAR f_norm_arg tCOMMA f_marg_list
{
- raise "no14: #{val.inspect}"
+ raise "no14\non: #{val.inspect}"
}
| tSTAR
{
- raise "no15: #{val.inspect}"
+ raise "no15\non: #{val.inspect}"
}
| tSTAR tCOMMA f_marg_list
{
- raise "no16: #{val.inspect}"
+ raise "no16\non: #{val.inspect}"
}
block_param: f_arg tCOMMA f_block_optarg tCOMMA f_rest_arg opt_f_block_arg
{
result = block_args19 val, "1"
@@ -1251,11 +1256,16 @@
{
result = block_args19 val, "2"
}
| f_arg tCOMMA f_block_optarg opt_f_block_arg
{
- result = block_args19 val, "3"
+ arg, _, opt, block = val
+
+ result = arg
+ result.concat opt[1..-1].map { |s| s[1] }
+ result << "&#{block.last}".to_sym if block
+ result << opt
}
| f_arg tCOMMA f_block_optarg tCOMMA f_arg opt_f_block_arg
{
result = block_args19 val, "4"
}
@@ -1283,11 +1293,16 @@
{
result = block_args19 val, "10"
}
| f_block_optarg opt_f_block_arg
{
- result = block_args19 val, "11"
+ opt, block = val
+
+ result = s(:args)
+ result.concat opt[1..-1].map { |s| s[1] }
+ result << "&#{block.last}".to_sym if block
+ result << opt
}
| f_block_optarg tCOMMA f_arg opt_f_block_arg
{
result = block_args19 val, "12"
}
@@ -1295,11 +1310,15 @@
{
result = block_args19 val, "13"
}
| f_rest_arg tCOMMA f_arg opt_f_block_arg
{
- result = block_args19 val, "14"
+ rest, _, args, block = val
+
+ result = args
+ result[1,0] = rest
+ result << "&#{block.last}".to_sym if block
}
| f_block_arg
{
result = block_args19 val, "15"
}
@@ -1327,14 +1346,17 @@
{
result = val[1]
}
bv_decls: bvar
+ {
+ result = [val[0]]
+ }
| bv_decls tCOMMA bvar
{
- result = val[0] << val[2]
- raise "no18: #{val.inspect}"
+ result = val[0].concat val[2]
+ raise "no18\non: #{val.inspect}"
}
bvar: tIDENTIFIER
| f_bad_arg
@@ -1391,13 +1413,17 @@
self.env.unextend
}
block_call: command do_block
{
- raise SyntaxError, "Both block arg and actual block given." if
- val[0] && val[0][0] == :blockpass
+ # TODO:
+ # if (nd_type($1) == NODE_YIELD) {
+ # compile_error(PARSER_ARG "block given to yield");
+ syntax_error "Both block arg and actual block given." if
+ val[0].block_pass?
+
result = val[1]
result.insert 1, val[0]
}
| block_call tDOT operation2 opt_paren_args
{
@@ -1922,12 +1948,16 @@
{
result = self.assignable val[0], val[2]
}
f_block_optarg: f_block_opt
+ {
+ result = s(:block, val[0])
+ }
| f_block_optarg tCOMMA f_block_opt
{
- raise "no22: #{val.inspect}"
+ result = val[0]
+ result << val[2]
}
f_optarg: f_opt
{
result = s(:block, val[0])