Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve interpolated raw string literal parsing #283

Closed
tamasvajk opened this issue Jan 12, 2023 · 3 comments · Fixed by #333
Closed

Improve interpolated raw string literal parsing #283

tamasvajk opened this issue Jan 12, 2023 · 3 comments · Fixed by #333

Comments

@tamasvajk
Copy link
Collaborator

The below sample produces a parsing error:

int x = 1;
var a = $$""""
    aaa
    {
    """
    {{x}}
    """
    }
    bbb
    """";
System.Console.WriteLine(a);

I think the only option is to handle this case in an external scanner. That could keep track of the number of $, " and { symbols.

@damieng
Copy link
Collaborator

damieng commented Jan 12, 2023

I suspect we're also going to need an external scanner for XML doc literals.

@tamasvajk
Copy link
Collaborator Author

@amaanq I see that #333 will close this issue, but I don't think the issue is completely solved. I'm getting the below tree on the above code fragment:

❯ tree-sitter parse a.cs
(compilation_unit [0, 0] - [10, 28]
  (global_statement [0, 0] - [0, 10]
    (local_declaration_statement [0, 0] - [0, 10]
      (variable_declaration [0, 0] - [0, 9]
        type: (predefined_type [0, 0] - [0, 3])
        (variable_declarator [0, 4] - [0, 9]
          name: (identifier [0, 4] - [0, 5])
          (integer_literal [0, 8] - [0, 9])))))
  (global_statement [1, 0] - [4, 7]
    (local_declaration_statement [1, 0] - [4, 7]
      (variable_declaration [1, 0] - [4, 7]
        type: (implicit_type [1, 0] - [1, 3])
        (variable_declarator [1, 4] - [4, 7]
          name: (identifier [1, 4] - [1, 5])
          (interpolated_string_expression [1, 8] - [4, 7]
            (interpolation_dollar [1, 8] - [1, 10])
            (string_content [1, 13] - [3, 4])
            (string_content [3, 4] - [4, 4]))))))
  (ERROR [5, 4] - [9, 9]
    (initializer_expression [5, 4] - [5, 9]
      (initializer_expression [5, 5] - [5, 8]
        (identifier [5, 6] - [5, 7]))))
  (global_statement [10, 0] - [10, 28]
    (local_declaration_statement [10, 0] - [10, 28]
      (variable_declaration [10, 0] - [10, 27]
        type: (qualified_name [10, 0] - [10, 24]
          qualifier: (qualified_name [10, 0] - [10, 14]
            qualifier: (identifier [10, 0] - [10, 6])
            name: (identifier [10, 7] - [10, 14]))
          name: (identifier [10, 15] - [10, 24]))
        (variable_declarator [10, 24] - [10, 27]
          (tuple_pattern [10, 24] - [10, 27]
            name: (identifier [10, 25] - [10, 26])))))))
a.cs    0 ms    (MISSING ";" [4, 7] - [4, 7])

@amaanq
Copy link
Member

amaanq commented May 2, 2024

updated, I hadn't even noticed the 4 quotes nor was it mentioned on the MS docs, but I found a different page that briefly mentioned it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants