Skip to content

Rewrite using tree-sitter #46

Open

Description

@krlmlr

Seems feasible, powerful, and fun. Could become a reformatter for roxygen2 code too, with optional sentence wrapping using https://github.com/segment-any-text/wtpsplit or another library.

@TymekDev: Are you open to sharing your approach and code for tree-sitter-roxygen2?

Activity

  1. TymekDev commented on Jun 13, 2025

    @TymekDev

    Sure! I don't really have any code to share as I barely scratched the surface. However, I can share some insights.

    1. I think the grammar should work similarly to JSDoc. This way, the leading part until #' gets omitted and we are left with repeated @tag <arguments> structure.
    2. The grammar needs to take into account that tag arguments can span multiple lines.
    3. Implicit title and description (and details?) seemed to be tricky to handle. I would start with handling explicit tags, and eventually go back to handling those as a special case.
    4. There are a few different tag categories that I would distinguish: no arguments (e.g., @noRd, @export), one argument (e.g., @import, @inheritParams), and multiple arguments (e.g., @param, @importFrom).
      1. Perhaps it would be pragmatic to start with just no arguments and some arguments.
      2. Eventually some of the tags could have more detailed grammar. For example: @importFrom could distinguish the package name and functions; @param could have multiple variants for "x" and "x,y", and the description could have markdown injected.
    5. I remember I was exploring how roxygen2 parses things and I have a vague memory of shenanigans around "invalid" things like #' @noRd something. I am not sure if the tree-sitter grammar should concern itself with it in any way, though. I guess the bottom line is: how many edge cases which roxygen2 lets slip the grammar should reflect?

    Overall, I would imagine the grammar to be a number of repeated tag nodes where each node either has no arguments or some arguments—this way, I think, we would end up with node starting with @someTag and ending just before (or a line before) the next @otherTag.

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

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