tree-sitter / tree-sitter-rust

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

bug: First-line inner attribute item is regarded as shebang #204

Closed monaqa closed 9 months ago

monaqa commented 9 months ago

Did you check existing issues?

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.20.8

Describe the bug

If the first (non-blank / non-comment) line starts with #!, even if it should be parsed as an inner_attribute_item, it is regarded as a shebang.

Steps To Reproduce/Bad Parse Tree

(source_file [0, 0] - [3, 0]
  (shebang [0, 0] - [0, 27])
  (function_item [2, 0] - [2, 12]
    name: (identifier [2, 3] - [2, 7])
    parameters: (parameters [2, 7] - [2, 9])
    body: (block [2, 10] - [2, 12])))

Expected Behavior/Parse Tree

(source_file [0, 0] - [3, 0]
  (inner_attribute_item [0, 0] - [0, 27]
    (attribute [0, 3] - [0, 26]
      (identifier [0, 3] - [0, 8])
      arguments: (token_tree [0, 8] - [0, 26]
        (identifier [0, 9] - [0, 25]))))
  (function_item [2, 0] - [2, 12]
    name: (identifier [2, 3] - [2, 7])
    parameters: (parameters [2, 7] - [2, 9])
    body: (block [2, 10] - [2, 12])))

Repro

#![allow(unused_variables)]

fn main() {}
amaanq commented 9 months ago

Thanks, fixed on master

monaqa commented 9 months ago

Thanks for the quick fix!