tree-sitter / tree-sitter-rust

Rust grammar for tree-sitter
MIT License
338 stars 96 forks source link

macro_invocation incorrectly parsed #190

Closed luckasRanarison closed 11 months ago

luckasRanarison commented 11 months ago

Tried parsing:

lazy_static! {
    static ref SOMETHING: Vec<u32> = vec![1, 2, 3];
}

There is an ERROR node and the nodes are out of order.

TSPlayground output:

macro_invocation [0, 0] - [2, 1]
  macro: identifier [0, 0] - [0, 11]
  token_tree [0, 13] - [2, 1]
    expression_statement [0, 13] - [2, 1]
      block [0, 13] - [2, 1]
        ERROR [1, 4] - [1, 41]
        empty_statement [1, 50] - [1, 51]
    identifier [1, 11] - [1, 14]
    identifier [1, 15] - [1, 24]
    identifier [1, 26] - [1, 29]
    primitive_type [1, 30] - [1, 33]
    identifier [1, 37] - [1, 40]
    token_tree [1, 41] - [1, 50]
      integer_literal [1, 42] - [1, 43]
      integer_literal [1, 45] - [1, 46]
      integer_literal [1, 48] - [1, 49]
luckasRanarison commented 11 months ago

Oh, sorry I've been using the parser from nvim-treesitter but I've tried from the source and there's no issue. For some reason the nvim-treesitter rust parser is not synced with this repo.

(source_file [0, 0] - [3, 0]
  (macro_invocation [0, 0] - [2, 1]
    macro: (identifier [0, 0] - [0, 11])
    (token_tree [0, 13] - [2, 1]
      (identifier [1, 11] - [1, 14])
      (identifier [1, 15] - [1, 24])
      (identifier [1, 26] - [1, 29])
      (primitive_type [1, 30] - [1, 33])
      (identifier [1, 37] - [1, 40])
      (token_tree [1, 41] - [1, 50]
        (integer_literal [1, 42] - [1, 43])
        (integer_literal [1, 45] - [1, 46])
        (integer_literal [1, 48] - [1, 49])))))

Closing this issue.

amaanq commented 11 months ago

Yeah do not use neovim output for issues here, please use the cli - the issue is neovim injects rust inside a macro's body, which can be useful a lot of the times but will cause errors.