2020-08-06 20:58:47 +03:00
|
|
|
# SLQ Grammar
|
|
|
|
|
2021-02-20 09:22:35 +03:00
|
|
|
The query language used by `sq` is formally known as _SLQ_. The
|
2020-08-06 20:58:47 +03:00
|
|
|
grammar is defined in `SLQ.g4`, which is an [ANTLR4](https://www.antlr.org/) grammar.
|
|
|
|
|
2022-12-24 19:43:21 +03:00
|
|
|
There's a bunch of valid sample input in the `testdata` dir.
|
|
|
|
|
2021-02-20 09:22:35 +03:00
|
|
|
The `antlr4` tool generates the parser / lexer files from the grammar.
|
|
|
|
Being that `antlr4` is Java-based, Java must be installed to regenerate
|
2022-12-24 19:43:21 +03:00
|
|
|
from the grammar. The process is encapsulated in `generate.sh` (or execute
|
|
|
|
`go generate ./...`).
|
2020-08-06 20:58:47 +03:00
|
|
|
|
2022-12-24 19:43:21 +03:00
|
|
|
The generated `.go` files ultimately end up in package `libsq/ast/internal/slq`. Files
|
2021-02-20 09:22:35 +03:00
|
|
|
in this directory should not be directly edited.
|
|
|
|
|
|
|
|
The `libsq/ast.Parse` function takes a `SLQ` input string and returns an `*ast.AST`.
|
2022-12-24 19:43:21 +03:00
|
|
|
The entrypoint that accepts the SLQ string is `libsq.ExecuteSLQ`, which ultimately
|
|
|
|
invokes `ast.Parse`.
|
|
|
|
|
|
|
|
## Working with the grammar
|
|
|
|
|
|
|
|
You probably should install the [antlr tools](https://github.com/antlr/antlr4-tools).
|
|
|
|
|
|
|
|
```shell
|
|
|
|
pip install antlr4-tools
|
|
|
|
```
|
|
|
|
|
|
|
|
You may also find [antlr4ts](https://github.com/tunnelvisionlabs/antlr4ts) useful.
|
|
|
|
|
|
|
|
```shell
|
|
|
|
npm install antlr4ts
|
|
|
|
```
|
|
|
|
|
|
|
|
And there are various [IDE plugins](https://github.com/antlr/antlr4-tools) available.
|
2020-08-06 20:58:47 +03:00
|
|
|
|
2022-12-24 19:43:21 +03:00
|
|
|
In particular, note the [VS Code extension](https://github.com/mike-lischke/vscode-antlr4).
|
2020-08-06 20:58:47 +03:00
|
|
|
|