sq/grammar
Neil O'Toole 2ba633fc2a
#258: Alias can be an arbitrary string. (#259)
* Fixed space issues with expressions

* Alias can now be an arbitrary string

* Alias can now be an arbitrary string (fixed)

* Alias now automatically applied to expressions

* Ignore .run

* Fixed issue with TestRun not logging correctly to testing.T

* Fiddling with sqlite3 temp file closing

* Re-enable tests
2023-06-18 00:05:09 -06:00
..
testdata SLQ support for column aliases (#150) 2023-03-18 22:58:00 -06:00
antlr-4.12.0-complete.jar Chore/upgrade to antlr 4.12.0 (#149) 2023-03-15 20:53:40 -06:00
generate.go Clean up the antlr tooling (#131) 2022-12-24 09:43:21 -07:00
generate.sh Chore/upgrade to antlr 4.12.0 (#149) 2023-03-15 20:53:40 -06:00
README.md Clean up the antlr tooling (#131) 2022-12-24 09:43:21 -07:00
SLQ.g4 #258: Alias can be an arbitrary string. (#259) 2023-06-18 00:05:09 -06:00

SLQ Grammar

The query language used by sq is formally known as SLQ. The grammar is defined in SLQ.g4, which is an ANTLR4 grammar.

There's a bunch of valid sample input in the testdata dir.

The antlr4 tool generates the parser / lexer files from the grammar. Being that antlr4 is Java-based, Java must be installed to regenerate from the grammar. The process is encapsulated in generate.sh (or execute go generate ./...).

The generated .go files ultimately end up in package libsq/ast/internal/slq. Files in this directory should not be directly edited.

The libsq/ast.Parse function takes a SLQ input string and returns an *ast.AST. 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.

pip install antlr4-tools

You may also find antlr4ts useful.

npm install antlr4ts

And there are various IDE plugins available.

In particular, note the VS Code extension.