Skip to content

Support for SQL parser - #1403

Closed
DerekStride wants to merge 1 commit into
nvim-treesitter:masterfrom
DerekStride:sql-parser
Closed

DerekStride wants to merge 1 commit into
nvim-treesitter:masterfrom
DerekStride:sql-parser

Conversation

@DerekStride

Copy link
Copy Markdown
Contributor

What

I've been implementing a parser for SQL, specifically targeted at MySQL but right now it's pretty general.

https://github.com/derekstride/tree-sitter-sql

I'm opening this PR to act as an RFC for suggestions as this is my first time writing a grammar and subsequently writing the highlight queries for it.

@DerekStride DerekStride changed the title [WIP] Support for SQL parser Support for SQL parser Jun 23, 2021
@Mange

Mange commented Sep 6, 2021

Copy link
Copy Markdown

This interests me. Anyway I can help out with this?

@DerekStride

DerekStride commented Sep 13, 2021 •

Copy link
Copy Markdown
Contributor Author

Thanks for the offer @Mange, I've been fairly busy and haven't had the chance to finish adding all the highlight groups. A lot of changes have been made since I first opened this PR. If you could update the revision to the latest, pull in all the new keywords and make sure the existing highlights work that would be great. I'm fairly sure some of the function_call nodes need to be updated.

Maybe try to see if there's anything missing on some of the more gnarly queries from the tree-sitter-sql tests.

I'm not too sure how complete the first pass needs to be. @theHamsta how much of the highlighting would you expect to be complete in a first pass? Getting every edge case seems to me to be high barrier for each new language, am I correct to assume we can incrementally add new highlight groups as we go?

@Mange

Mange commented Sep 15, 2021

Copy link
Copy Markdown

I'll see if I can allocate some time to this. Thanks!

@Mange

Mange commented Sep 29, 2021 •

Copy link
Copy Markdown

I forked my own version and rebased your commit on latest master, then I updated the revision.

I'm not sure how to proceed from here. The SCM-files are very hard to understand for me, and it's very unclear to me what needs to be done for function_call.

Is this correct?

(function_call
  name: (identifier)? @function
  parameter: [
    (field)
    (function_call)
    (literal)
    (predicate)
  ]? @parameter)

I based it on this:

https://github.com/DerekStride/tree-sitter-sql/blob/ce87c5d574abdf3b0b9779f92b757e7ae1decb2f/src/node-types.json#L1207-L1243

I could perhaps progress a bit more with some direction on what to do here. Is there some easy way to extract all the new keywords from the node-types.json file to add to highlights.scm?

[EDIT:] My fork is here https://github.com/Mange/nvim-treesitter/tree/sql-parser

@theHamsta

theHamsta commented Sep 29, 2021 •

Copy link
Copy Markdown
Member

@Mange your query looks ok. There is a nvim API function to list all anonymous nodes a of a language (search for vim.treesitter.inspect_language, it is also used by the query longer in nvim-treesitter/playground: https://github.com/nvim-treesitter/playground/blob/787a7a8d4444e58467d6b3d4b88a497e7d494643/lua/nvim-treesitter-playground/query_linter.lua#L71). The playground should also be best to see the parser tree of a language and to test queries.

Probably faster is to go through the string literals in grammar.js. Every string literal is typically mapped to a key word of the language.

@theHamsta

Copy link
Copy Markdown
Member

@DerekStride are you still planing to submit this?

@DerekStride

Copy link
Copy Markdown
Contributor Author

Not anytime soon, I'll close it for now and re-open it if I circle back around

@clason clason mentioned this pull request Jan 18, 2022
9 of 14 tasks
@stephane-klein

Copy link
Copy Markdown

I forked my own version and rebased your commit on latest master, then I updated the revision.

@Mange Have you do some progress on your merge request ?

@Mange

Mange commented Jan 27, 2022

Copy link
Copy Markdown

I forked my own version and rebased your commit on latest master, then I updated the revision.

@Mange Have you do some progress on your merge request ?

No, I abandoned it. I didn't know what I was doing and didn't have time to learn everything about treesitter and how Neovim integrates it.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants