On Saturday, October 12, 2013 at 5:37 PM, Stefan Monnier wrote:
In Ruby one can invoke methods with or without parentheses:
some_method(arg1, arg2)
some_method arg1, arg2
Interesting. How is the following parsed, then:
some_method arg1, other_method arg2, arg3, arg4
There are some limitations, of course. Ambiguous cases generally result in parsing errors:
Parser::CurrentRuby.parse('some_method arg1, other_method arg2, arg3, arg4')
(string):1:32: error: unexpected token tIDENTIFIER
some_method arg1, other_method arg2, arg3, arg4
^^^^
Parser::SyntaxError: unexpected token tIDENTIFIER
If we remove arg1, however, there is no ambiguity:
[21] pry(main)> Parser::CurrentRuby.parse('some_method other_method arg2, arg3, arg4')
=> (send nil :some_method
(send nil :other_method
(send nil :arg2)
(send nil :arg3)
(send nil :arg4)))