Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby dot call syntax accepts errant extra set of arguments #73

Open
haileys opened this issue Apr 10, 2018 · 1 comment
Open

Ruby dot call syntax accepts errant extra set of arguments #73

haileys opened this issue Apr 10, 2018 · 1 comment

Comments

@haileys
Copy link

haileys commented Apr 10, 2018

The grammar accepts the following code:

x.(123)(456)

And produces the following syntax tree:

(program [0, 0] - [1, 0]
  (method_call [0, 0] - [0, 12]
    (call [0, 0] - [0, 7]
      (identifier [0, 0] - [0, 1])
      (argument_list_with_parens [0, 2] - [0, 7]
        (integer [0, 3] - [0, 6])))
    (argument_list [0, 7] - [0, 12]
      (integer [0, 8] - [0, 11]))))

This is because the call rule accepts dot-call syntax including argument list, but method_call unconditionally sequences call with another argument list:

call: $ => prec.left(PREC.BITWISE_AND + 1, seq(
  $._primary,
  choice('.', '&.'),
  repeat($.heredoc_end),
  choice($.identifier, $.operator, $.constant, $.argument_list_with_parens)
)),

method_call: $ => {
  const receiver = choice($._variable, $.scope_resolution, $.call)

  return choice(
    seq(receiver, $.argument_list),
    seq(receiver, prec(PREC.CURLY_BLOCK, seq($.argument_list, $.block))),
    seq(receiver, prec(PREC.DO_BLOCK, seq($.argument_list, $.do_block))),
    prec(PREC.CURLY_BLOCK, seq(receiver, $.block)),
    prec(PREC.DO_BLOCK, seq(receiver, $.do_block))
  )
},

By comparison, Ruby rejects the example code:

$ ruby -c -e 'x.(123)(456)'
-e:1: syntax error, unexpected '(', expecting end-of-input
x.(123)(456)
        ^
@maxbrunsfeld
Copy link
Contributor

This is still true.

In general, I don't consider it a huge priority to avoid accepting invalid code, but I'd be open to a change that tightens the grammar in some way to disallow this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants