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

Machine-readable output of parser generation errors #3182

Open
yanok opened this issue Mar 15, 2024 · 2 comments
Open

Machine-readable output of parser generation errors #3182

yanok opened this issue Mar 15, 2024 · 2 comments
Labels
cli enhancement Feature request
Milestone

Comments

@yanok
Copy link

yanok commented Mar 15, 2024

Problem

Tree-sitter is doing a great job then reporting problems with the grammar (I'm currently mostly interested in conflicts), I really like the presentation and having possible resolutions, thanks!

But for the problem I'm trying to solve currently, it would be super handy to be able to get this information in machine-readable format (I was thinking about JSON, but doesn't really matter much). Of course, I can parse the current tree-sitter output to extract the needed information, but that seems a bit backwards: why would I parse strings that were pretty printed for me just moments ago?

So, I was thinking about adding something like --json-errors flag to the generate command. I could, of course, just do it in my fork, but I was wondering if that's something that could be also accepted upstream.

Expected behavior

tree-sitter generate --json-errors reports conflicts (and potentially other problems with the grammar) in JSON format, something like:

{
  "UnresolvedConflict": {
      "conflictingRules": ["foo", "bar"],
      "symbolSequence": {
          "stack": ["X", "Y"],
          "lookahead": "!",
      },
     "possibleInterpretations": [ ... ],
     "possibleResolutions": [ ... ],
   }
}
@yanok yanok added the enhancement Feature request label Mar 15, 2024
@maxbrunsfeld
Copy link
Contributor

That seems like a good feature to add!

@ObserverOfTime
Copy link
Member

Machine-readable output of parsing results would also be nice to have.

{
  "results": [
    {
      "file": "foo",
      "result": "SUCCESS|ERROR|MISSING|UNEXPECTED",
      "start": [0, 0],
      "end": [1, 1],
      "time": 0.1, // ms
      "bytes": 1000 // bytes/ms
    },
    ...
  ],
  "total": 1,
  "successful": 1,
  "failed": 0,
  "speed": 1000 // bytes/ms
}

@ObserverOfTime ObserverOfTime added this to the 1.0 milestone Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli enhancement Feature request
Projects
None yet
Development

No branches or pull requests

3 participants