Skip to content

Zsh-like globs produce parse error – multiple issues in Zed, nvim-treesitter, emacs, etc #328

@abghim

Description

@abghim

I came across this Zed issue recently (51555). The example below is taken directly from that issue.

Parse Bug

Zsh-like globs (line 4 in the following code) produce an incorrect parse tree.

env_loader_loop() {
    local -a files

    files=("$SRC_CFG_DIR"/*.sh(N))

    if ((${#files[@]} == 0)); then
        msg --warn "no *.sh files found in '$SRC_CFG_DIR'"
        return 0
    fi
}

This produces

(program
  (function_definition
    name: (word)
    body: (compound_statement
      (declaration_command
        (word)
        (variable_name))
      (variable_assignment
        name: (variable_name)
        value: (array
          (concatenation
            (string
              (simple_expansion
                (variable_name)))
            (word)
            (ERROR
              (word))
            (expansion
              (subscript
                name: (variable_name)
                index: (word))))
          (word)
          (number)))
      (ERROR)
      (command
        name: (command_name
          (word)))
      (command
        name: (command_name
          (word))
        argument: (word)
        argument: (string
          (string_content)
          (simple_expansion
            (variable_name))
          (string_content)))
      (command
        name: (command_name
          (word))
        argument: (number))
      (command
        name: (command_name
          (word))))))

I totally understand if the devs are reluctant to have this a priority – this is, after all, the bash-compatible parser and not for zsh. I still decided to open this issue because many programs that depend critically on tree-sitter see seriously broken parses in zsh config files and scripts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions