m-novikov/tree-sitter-sql

SQL syntax highlighting for tree-sitter

126

stars

176

commits

JavaScript

primary language

Mar 6, 2024

updated

grammar
parser
sql
syntax
syntax-highlighting
tree-sitter

README

Node.js CI

SQL syntax for tree-sitter

This project initially focuses on PostgreSQL flavor of SQL

Try it out

You can try out the parser here: Tree Sitter SQL Playground

Development

Install pre-commit and run pre-commit install in the root of this repo. This will ensure that code follows code style of this repo.

File describing grammar is grammar.js

Every time the grammar file changes code generation needs to be run by invoking npm run gen

npm test command automatically performs code generation

Tests files are located in test/corpus

Here is the documentation on test file syntax

Running tests

npm install --also=dev
npm test

Debbuging

  • npm run parse <file.sql> outputs a syntax tree
  • npm run extract-error <file.sql> shows first offending line

Goals

This parser is supposed to be used in text editors. As a result:

  • it's very lax in what it considers valid SQL parse
  • adding extra nodes to have convenient selection anchors is okay

Other projects

Contributors

m-novikov

152 commits

pplam

14 commits

cfabianski

4 commits

nokome

2 commits

m-novikov/tree-sitter-sql

SQL syntax highlighting for tree-sitter

126

stars

176

commits

JavaScript

primary language

Mar 6, 2024

updated

grammar
parser
sql
syntax
syntax-highlighting
tree-sitter

README

Node.js CI

SQL syntax for tree-sitter

This project initially focuses on PostgreSQL flavor of SQL

Try it out

You can try out the parser here: Tree Sitter SQL Playground

Development

Install pre-commit and run pre-commit install in the root of this repo. This will ensure that code follows code style of this repo.

File describing grammar is grammar.js

Every time the grammar file changes code generation needs to be run by invoking npm run gen

npm test command automatically performs code generation

Tests files are located in test/corpus

Here is the documentation on test file syntax

Running tests

npm install --also=dev
npm test

Debbuging

  • npm run parse <file.sql> outputs a syntax tree
  • npm run extract-error <file.sql> shows first offending line

Goals

This parser is supposed to be used in text editors. As a result:

  • it's very lax in what it considers valid SQL parse
  • adding extra nodes to have convenient selection anchors is okay

Other projects

Contributors

m-novikov

152 commits

pplam

14 commits

cfabianski

4 commits

nokome

2 commits

Languages

JavaScript

86.5%

Rust

6.3%

Scheme

4.7%

C++

1.8%