zeek / zeek/zeekscript

Function calls incorrectly formatted

Open
#69 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
11
Forks
4
Avg merge
3d 19h
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with the shown Zeek snippets and the tree-sitter parse command. Trace the expression and function-call parsing and formatting behavior; done means adjacent calls produce the correct CST, long call chains no longer break inside arguments, and all calls can be matched for inlay hints.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.