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

Incorrectly parsed ternary_expression #303

Open
ketkarameya opened this issue Jul 12, 2023 · 1 comment
Open

Incorrectly parsed ternary_expression #303

ketkarameya opened this issue Jul 12, 2023 · 1 comment

Comments

@ketkarameya
Copy link
Contributor

ketkarameya commented Jul 12, 2023

I observed that if a ternary expression is like - false ? "foo" : nil (note the nil), the if_false field does not get populated.

However it works if the the alternative was an expression other than nil ... false ? "foo" : "y" parses ok.

I wonder why nil is not parsed as an expression here - https://github.com/alex-pinkus/tree-sitter-swift/blob/main/grammar.js#L795

@ketkarameya
Copy link
Contributor Author

ketkarameya commented Jul 12, 2023

also observed that

  • if_true field is not populated if the ternary was something like false? nil : x
  • both if_false and if_false are not populated when false ? nil: nil

After tinkering for sometime, i observed that "nil" is the only value for which i observe such a behavior.

Tried to update to _expr_hack_at_ternary_binary_suffix to :

_expr_hack_at_ternary_binary_suffix: ($) =>
      prec.left(
        PRECS.ternary_binary_suffix,
        choice(
          "nil",
          $._expression,
          alias($.expr_hack_at_ternary_binary_call, $.call_expression)
        )
      )

Didnt work :|

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

1 participant