Skip to content

Wrong precedence for RangeFrom in for loop #121

@narpfel

Description

@narpfel

Example:

fn main() {
    for i in 1.. {
        println!("{}", i)
    }
}

This should parse 1.. as the loop’s iterator and the block as the loop’s block, but instead tree-sitter parses 1..{ <block> } as the loop’s iterator, which results in a parse error:

$ tree-sitter parse main.rs
(source_file [0, 0] - [5, 0]
  (function_item [0, 0] - [4, 1]
    name: (identifier [0, 3] - [0, 7])
    parameters: (parameters [0, 7] - [0, 9])
    body: (block [0, 10] - [4, 1]
      (ERROR [1, 4] - [3, 5]
        (identifier [1, 8] - [1, 9])
        (range_expression [1, 13] - [3, 5]
          (integer_literal [1, 13] - [1, 14])
          (block [1, 17] - [3, 5]
            (macro_invocation [2, 8] - [2, 25]
              macro: (identifier [2, 8] - [2, 15])
              (token_tree [2, 16] - [2, 25]
                (string_literal [2, 17] - [2, 21])
                (identifier [2, 23] - [2, 24])))))))))
main.rs 0 ms    (ERROR [1, 4] - [3, 5])

Expected:

(source_file [0, 0] - [5, 0]
  (function_item [0, 0] - [4, 1]
    name: (identifier [0, 3] - [0, 7])
    parameters: (parameters [0, 7] - [0, 9])
    body: (block [0, 10] - [4, 1]
      (for_expression [1, 4] - [3, 5]
        pattern: (identifier [1, 8] - [1, 9])
        value: (range_expression [1, 13] - [1, 17]
          (integer_literal [1, 13] - [1, 14]))
        body: (block [1, 17] - [3, 5]
          (macro_invocation [2, 8] - [2, 25]
            macro: (identifier [2, 8] - [2, 15])
            (token_tree [2, 16] - [2, 25]
              (string_literal [2, 17] - [2, 21])
              (identifier [2, 23] - [2, 24]))))))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions