# KSQL parser

We use the grammar from the KSQL project compiled to javascript to handle parsing, dependency
extraction and resolution, pretty printing, and replacement(eg, partitions/timezones).


## Guidelines

Due to the way antlr4 generated output is consumed we should not modify generated files, they
serve as the base to inherit from and should not be modified after being generated or updated.
The general concept we are working with is the extraction of what stream each query provides and
which streams are consumed.  That data allows us to generate a file with queries order by their
dependencies. Additionally we also know that the specific syntax of each query is correct because
the same parser code should be used by the server, this does *not* imply that the queries will
all work without errors only that they are syntactically correct according to the KSQL grammar.

## Updates
to update the grammar grab the latest version of SqlBase.g4 from the
[ksql source](https://github.com/confluentinc/ksql/blob/master/ksql-parser/src/main/antlr4/io/confluent/ksql/parser/SqlBase.g4)
and place it in this directory. 

run antlr4:
```bash
antlr4 -Dlanguage=JavaScript SqlBase.g4
```
or in the project root run
```bash
yarn grammar
```
*NOTE*: the grammar may need to be tweaked to allow lowercase identifiers by adding `a-z` to the
definition of `fragment LETTER`

## License

Copyright 2019 Carnegie Technologies

Sources generated by antlr4 are derivative works of the upstream SqlBase.g4 which is licensed 
under the [Confluent Community License](https://www.confluent.io/confluent-community-license/) [also here](./LICENSE-Grammar).

Everything else is licensed under the [Apache 2 License](../LICENSE)