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

Function calls incorrectly formatted #69

Open
bbannier opened this issue Dec 16, 2023 · 0 comments
Open

Function calls incorrectly formatted #69

bbannier opened this issue Dec 16, 2023 · 0 comments
Labels
bug Something isn't working

Comments

@bbannier
Copy link
Member

bbannier commented Dec 16, 2023

When many function calls are part of the same expression they can be broken incorrectly, e.g., the following input

f(1) + f(1) +
f(1) + f(1) +
f(1) + f(1) +
f(1) + f(1) +
f(1) + f(1) +
f(1) + f(1) +
f(1) + f(1) +
f(1) + f(1);

is formatted with a line break inside the function call

f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(1) + f(
    1) + f(1) + f(1) + f(1);

Looking at the produced CST this seems to be due to function calls in expressions not parsing correctly, e.g., with

f(1) + f(1);

I get

$ tree-sitter parse foo.zeek
(source_file [0, 0] - [1, 0]
  (stmt [0, 0] - [0, 12]
    (expr [0, 0] - [0, 11]
      (expr [0, 0] - [0, 8]
        (expr [0, 0] - [0, 4]
          (expr [0, 0] - [0, 1]
            (id [0, 0] - [0, 1]))
          (expr_list [0, 2] - [0, 3]
            (expr [0, 2] - [0, 3]
              (constant [0, 2] - [0, 3]
                (integer [0, 2] - [0, 3])))))
        (expr [0, 7] - [0, 8]
          (id [0, 7] - [0, 8])))
      (expr_list [0, 9] - [0, 10]
        (expr [0, 9] - [0, 10]
          (constant [0, 9] - [0, 10]
            (integer [0, 9] - [0, 10]))))))
  (nl [0, 12] - [1, 0]))

If this had correct precedence I would expect two nodes (expr (expr (id)) (expr_list ...) next to each other; instead the function name of the second f gets incorrectly grouped next to the arguments of the first call.

The current "lightweight" impl also makes it impossible to match multiple function calls in the same expression, e.g., over in https://github.com/bbannier/zeek-language-server I cannot match all calls to compute parameter inlay hints, e.g.,

Screenshot 2023-12-16 at 1 20 29 AM
@bbannier bbannier added the bug Something isn't working label Dec 16, 2023
bbannier added a commit to bbannier/tree-sitter-zeek that referenced this issue Dec 16, 2023
This works around the issue reported in zeek/zeekscript#69.
bbannier added a commit to zeek/tree-sitter-zeek that referenced this issue Jan 16, 2024
This works around the issue reported in zeek/zeekscript#69.
@bbannier bbannier reopened this Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant