tree-sitter / tree-sitter-julia

Julia grammar for Tree-sitter
MIT License
93 stars 32 forks source link

bug: macro docstrings are parsed just as strings #145

Closed ronisbr closed 1 month ago

ronisbr commented 1 month ago

Did you check existing issues?

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

No response

Describe the bug

The grammar parses correctly the docstring in a function:

"""
    test()

This is a docstring.

```julia
julia> teste()
\```
"""
function test()
end
(source_file ; [0, 0] - [11, 0]
  (string_literal ; [0, 0] - [8, 3]
    (document ; [0, 3] - [8, 0]
      (section ; [0, 3] - [8, 0]
        (indented_code_block) ; [1, 0] - [3, 0]
        (paragraph ; [3, 0] - [4, 0]
          (inline ; [3, 0] - [3, 20]
            (inline))) ; [3, 0] - [3, 20]
        (fenced_code_block ; [5, 0] - [8, 0]
          (fenced_code_block_delimiter) ; [5, 0] - [5, 3]
          (info_string ; [5, 3] - [5, 8]
            (language)) ; [5, 3] - [5, 8]
          (block_continuation) ; [6, 0] - [6, 0]
          (code_fence_content ; [6, 0] - [7, 0]
            (source_file ; [6, 0] - [7, 0]
              (binary_expression ; [6, 0] - [6, 14]
                (identifier) ; [6, 0] - [6, 5]
                (operator) ; [6, 5] - [6, 6]
                (call_expression ; [6, 7] - [6, 14]
                  (identifier) ; [6, 7] - [6, 12]
                  (argument_list)))) ; [6, 12] - [6, 14]
            (block_continuation)) ; [7, 0] - [7, 0]
          (fenced_code_block_delimiter))))) ; [7, 0] - [7, 3]
  (function_definition ; [9, 0] - [10, 3]
    (signature ; [9, 9] - [9, 15]
      (call_expression ; [9, 9] - [9, 15]
        (identifier) ; [9, 9] - [9, 13]
        (argument_list))))) ; [9, 13] - [9, 15]

However, the docstrings of macros are parsed just as a single string:

"""
    @test()

This is a docstring.

```julia
julia> @teste()
\```
"""
macro test()
end
(source_file ; [0, 0] - [11, 0]
  (string_literal) ; [0, 0] - [8, 3]
  (macro_definition ; [9, 0] - [10, 3]
    (signature ; [9, 6] - [9, 12]
      (call_expression ; [9, 6] - [9, 12]
        (identifier) ; [9, 6] - [9, 10]
        (argument_list))))) ; [9, 10] - [9, 12]

Steps To Reproduce/Bad Parse Tree

  1. Write a docstring for a macro.
  2. Check the tree provided by the grammar.

Expected Behavior/Parse Tree

The docstrings of macros should be parsed like the grammar parses the docstrings of functions.

Repro

No response

savq commented 1 month ago

The parser doesn't do anything special here. The docstrings are parsed as markdown when the editor defines a language injection.

savq commented 1 month ago

Should be fixed now 🙂