Project

General

Profile

Actions

Bug #19281

closed

SyntaxError if first argument of command call has semicolon inside parenthesis

Added by tompng (tomoya ishida) about 1 year ago. Updated 7 months ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:111499]

Description

These are syntax error

p (1;2),(3),(4)
p (;),(),()
a.b (1;2),(3),(4)
a.b (;),(),()

I expect it to be syntax ok because the code below is syntax ok.

p (1),(2;3),(4;5)
p (),(;),(;)
a.b (1),(2;3),(4;5)
a.b (),(;),(;)

It will be easy to traverse sexp if the sexp of first argument is same as others

Ripper.sexp "p (),(),()"
# =>
[:program,
 [[:command,
   [:@ident, "p", [1, 0]],
   [:args_add_block,
    [[:paren, false], # [:paren, [[:void_stmt]]]
     [:paren, [[:void_stmt]]],
     [:paren, [[:void_stmt]]]],
    false]]]]
Ripper.sexp "p (1),(2),(3)"
# =>
[:program,
 [[:command,
   [:@ident, "p", [1, 0]],
   [:args_add_block,
    [[:paren, [:@int, "1", [1, 3]]], # [:paren, [[:@int, "1", [1, 3]]]]
     [:paren, [[:@int, "2", [1, 7]]]],
     [:paren, [[:@int, "3", [1, 11]]]]],
    false]]]]

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #6674: 1.9 parser regression: not ()Closedshugo (Shugo Maeda)06/30/2012Actions

Updated by jeremyevans0 (Jeremy Evans) 7 months ago

YARP parses all of these successfully:

YARP.parse("p (1;2),(3),(4)").success?
# => true
YARP.parse("p (;),(),()").success?
# => true
YARP.parse("a.b (1;2),(3),(4)").success?
# => true
YARP.parse("a.b (;),(),()").success?
# => true
Actions #2

Updated by nobu (Nobuyoshi Nakada) 7 months ago

  • Related to Bug #6674: 1.9 parser regression: not () added
Actions #3

Updated by yui-knk (Kaneko Yuichiro) 7 months ago

  • Status changed from Open to Closed

Applied in changeset git|45cd011d73ed1fac195d828c0565e2cac57f65fc.


[Bug #19281] Allow semicolon in parenthesis at the first argument of command call

Allow compstmt in the first argument of command call wrapped with parenthesis
like following arguments with parenthesis.

Updated by fxn (Xavier Noria) 7 months ago

From the point of view of the user, I believe the reasoning would be:

In a method call with parentheses, no spaces are allowed between the method name and the parenthesis that starts the argument list.

Each argument is an expression. In particular, each argument can be written as one or more statements if enclosed in parentheses (generic property of parenthesized expressions). Statements can be separated by newlines or ; (again, generic).

If there is a space after the method name, what follows is considered to be its argument list without surrounding parentheses. In particular, if there is a parenthesis after the space, that one is considered to start the expression of the first argument.

Makes sense?

So,

puts(1)
puts((1))

puts 1
puts (1)

are all the same structurally (mod tokens).

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0