Issue #19281 has been updated by fxn (Xavier Noria).
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
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 mehtod 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 an expression.
Makes sense?
So,
```ruby
puts(1)
puts((1))
puts 1
puts (1)
```
are all the same structurally (mod tokens).
----------------------------------------
Bug #19281: SyntaxError if first argument of command call has semicolon inside
parenthesis
https://bugs.ruby-lang.org/issues/19281#change-104450
* Author: tompng (tomoya ishida)
* Status: Closed
* Priority: Normal
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN
----------------------------------------
These are syntax error
~~~ruby
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.
~~~ruby
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
~~~ruby
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]]]]
~~~
--
https://bugs.ruby-lang.org/