Project

General

Profile

Feature #12686

Allowing a postposed rescue in a method argument

Added by sonots (Naotoshi Seo) about 3 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:76958]

Description

On defining my own DSL, I wanted to write a code like:

foo (Integer(ENV['FOO']) rescue nil)

where foo is a method which receives one argument , but I got following error

SyntaxError: (irb):1: syntax error, unexpected modifier_rescue, expecting ')'

In contrast, following codes were valid:

foo ((Integer(ENV['FOO']) rescue nil))

or

foo (begin; Integer(ENV['FOO']); rescue; nil; end)

This is a feature request to allow such a syntax, a postposed rescue in a method argument.

Associated revisions

Revision ec8f8fa4
Added by nobu (Nobuyoshi Nakada) about 3 years ago

parse.y: lparen_arg statement

  • parse.y (primary): allow parenthesised statement as a method argument. [Feature #12686]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55965 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 55965
Added by nobu (Nobuyoshi Nakada) about 3 years ago

parse.y: lparen_arg statement

  • parse.y (primary): allow parenthesised statement as a method argument. [Feature #12686]

Revision 55965
Added by nobu (Nobuyoshi Nakada) about 3 years ago

parse.y: lparen_arg statement

  • parse.y (primary): allow parenthesised statement as a method argument. [Feature #12686]

Revision 55965
Added by nobu (Nobuyoshi Nakada) about 3 years ago

parse.y: lparen_arg statement

  • parse.y (primary): allow parenthesised statement as a method argument. [Feature #12686]

Revision 55965
Added by nobu (Nobuyoshi Nakada) about 3 years ago

parse.y: lparen_arg statement

  • parse.y (primary): allow parenthesised statement as a method argument. [Feature #12686]

History

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

It sounds nothing wrong with it, to me.

diff --git i/parse.y w/parse.y
index 17f0f9c..7a14941 100644
--- i/parse.y
+++ w/parse.y
@@ -2659,7 +2659,7 @@ primary       : literal
            $<val>1 = cmdarg_stack;
            CMDARG_SET(0);
            }
-         expr {SET_LEX_STATE(EXPR_ENDARG);} rparen
+         stmt {SET_LEX_STATE(EXPR_ENDARG);} rparen
            {
            CMDARG_SET($<val>1);
            /*%%%*/
diff --git i/test/ruby/test_syntax.rb w/test/ruby/test_syntax.rb
index ce01358..9b5b9f1 100644
--- i/test/ruby/test_syntax.rb
+++ w/test/ruby/test_syntax.rb
@@ -827,6 +827,10 @@
     end
   end

+  def test_stmt_lparen_arg
+    assert_valid_syntax("foo (bar rescue nil)")
+  end
+
   private

   def not_label(x) @result = x; @not_label ||= nil end

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

tLPAREN_ARG has been introduced at 1.7, I think we can clear up spaces and parentheses rules now.

#4

Updated by nobu (Nobuyoshi Nakada) about 3 years ago

  • Status changed from Open to Closed

Applied in changeset r55965.


parse.y: lparen_arg statement

  • parse.y (primary): allow parenthesised statement as a method argument. [Feature #12686]

Also available in: Atom PDF