Tree-sitter: Recursive `token(rule)` gives unhelpful error

Created on 9 Jul 2019  路  2Comments  路  Source: tree-sitter/tree-sitter

{
  name: 'example',
  rules: {
    block_comment: $ => token(seq(
      "/*",
      repeat(choice($.block_comment, /[^*]*(?:\*[^/])?/)),
      "*/",
    )),
  },
}

processed JSON:

{
  "name": "example",
  "rules": {
    "block_comment": {
      "type": "TOKEN",
      "content": {
        "type": "SEQ",
        "members": [
          {
            "type": "STRING",
            "value": "/*"
          },
          {
            "type": "REPEAT",
            "content": {
              "type": "CHOICE",
              "members": [
                {
                  "type": "SYMBOL",
                  "name": "block_comment"
                },
                {
                  "type": "PATTERN",
                  "value": "[^*]*(?:\\*[^\\/])?"
                }
              ]
            }
          },
          {
            "type": "STRING",
            "value": "*/"
          }
        ]
      }
    }
  },
  "extras": [
    {
      "type": "PATTERN",
      "value": "\\s"
    }
  ],
  "conflicts": [],
  "externals": [],
  "inline": [],
  "supertypes": []
}

Given error:

~>tree-sitter generate
Error processing rule block_comment_token1
Details:
  Grammar error: Unexpected rule Symbol(Symbol { kind: NonTerminal, index: 0 })

Error appears to be from this line:
https://github.com/tree-sitter/tree-sitter/blob/d274e81d0df44334ec328958defa8631cefa4f35/cli/src/generate/prepare_grammar/expand_tokens.rs#L192

bug

Most helpful comment

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.96. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

All 2 comments

Issue-Label Bot is automatically applying the label bug to this issue, with a confidence of 0.96. Please mark this comment with :thumbsup: or :thumbsdown: to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

Not sure this problem is related to recursion. I opened #449.

Was this page helpful?
0 / 5 - 0 ratings