Skip to content

bug: string_content inside raw_string_literal doesn't match leading whitespaces #251

Open
@Nosterx

Description

@Nosterx

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-rust

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

tree-sitter 0.23.2

Describe the bug

whitespaces after r#" and before SELECT are not included in string_content

fn main() {
    let query = r#"
        SELECT * FROM users
    "#;
}

Steps To Reproduce/Bad Parse Tree

(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]
      (let_declaration ; [1, 4] - [3, 7]
        pattern: (identifier) ; [1, 8] - [1, 13]
        value: (raw_string_literal ; [1, 16] - [3, 6]
          (string_content ; [2, 8] - [3, 4]
            (program ; [2, 8] - [3, 4]
              (statement ; [2, 8] - [2, 27]
                (select ; [2, 8] - [2, 16]
                  (keyword_select) ; [2, 8] - [2, 14]
                  (select_expression ; [2, 15] - [2, 16]
                    (term ; [2, 15] - [2, 16]
                      value: (all_fields)))) ; [2, 15] - [2, 16]
                (from ; [2, 17] - [2, 27]
                  (keyword_from) ; [2, 17] - [2, 21]
                  (relation ; [2, 22] - [2, 27]
                    (object_reference ; [2, 22] - [2, 27]
                      name: (identifier)))))))))))) ; [2, 22] - [2, 27]

Expected Behavior/Parse Tree

(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]
      (let_declaration ; [1, 4] - [3, 7]
        pattern: (identifier) ; [1, 8] - [1, 13]
        value: (raw_string_literal ; [1, 16] - [3, 6]
          (string_content ; [1, 19] - [3, 4]
            (program ; [2, 8] - [3, 4]
              (statement ; [2, 8] - [2, 27]
                (select ; [2, 8] - [2, 16]
                  (keyword_select) ; [2, 8] - [2, 14]
                  (select_expression ; [2, 15] - [2, 16]
                    (term ; [2, 15] - [2, 16]
                      value: (all_fields)))) ; [2, 15] - [2, 16]
                (from ; [2, 17] - [2, 27]
                  (keyword_from) ; [2, 17] - [2, 21]
                  (relation ; [2, 22] - [2, 27]
                    (object_reference ; [2, 22] - [2, 27]
                      name: (identifier)))))))))))) ; [2, 22] - [2, 27]

different line is (string_content ; [1, 19] - [3, 4]

Repro

fn main() {
    let query = r#"
        SELECT * FROM users
    "#;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions