HyriseSQLParser/docs/dev-docs.md

64 lines
2.4 KiB
Markdown
Raw Permalink Normal View History

2014-12-16 02:23:56 +01:00
Developer Documentation
=======================
2014-12-15 18:32:46 +01:00
## Basic Requirements
**Requirements for development:**
* gcc 4.8+ (or clang 3.4+)
* [bison](https://www.gnu.org/software/bison/) (v3.0.2+)
* [flex](http://flex.sourceforge.net/) (v2.5.5+)
First step to extending this parser is cloning the repository `git clone git@github.com:hyrise/sql-parser.git` and making sure everything works by running the following steps:
```bash
make parser # builds the bison parser and flex lexer
make library # builds the libsqlparser.so
make test # runs the tests with the library
```
Rerun these steps whenever you change part of the parse. To execute the entire pipeline automatically you can run:
```bash
make cleanall # cleans the parser build and library build
make test # build parser, library and runs the tests
```
2016-02-27 16:58:51 +01:00
## Developing New Functionality
2014-12-15 18:32:46 +01:00
2016-02-27 16:58:51 +01:00
This section contains information about how to extend this parser with new functionalities.
2014-12-15 18:32:46 +01:00
2016-02-27 16:58:51 +01:00
### Implementing a new Statement
2014-12-16 02:23:56 +01:00
2020-05-17 04:54:22 +02:00
Create a new file and class in `src/sql/` or extend any of the existing Statements. Every statement needs to have the base class SQLStatement and needs to call its super constructor with its type. If you're defining a new statement type, you need to define a new StatementType in `SQLStatement.h`.
2014-12-16 02:23:56 +01:00
2020-05-17 04:54:22 +02:00
It is important that you create an appropriate constructor for your statement that zero-initializes all its pointer variables and that you create an appropriate destructor.
2014-12-16 02:23:56 +01:00
2016-02-27 16:58:51 +01:00
Finally you will need to include your new file in `src/sql/statements.h`.
2014-12-16 02:23:56 +01:00
2016-02-27 16:58:51 +01:00
### Extending the Grammar
2014-12-15 18:32:46 +01:00
2014-12-16 02:23:56 +01:00
Related files:
```
2016-02-27 16:58:51 +01:00
src/parser/bison_parser.y
src/parser/flex_lexer.l
src/parser/keywordlist_generator.py
src/parser/sql_keywords.txt
```
2014-12-15 18:32:46 +01:00
2016-02-27 16:58:51 +01:00
To extend the grammar the file you will mostly have to deal with is the bison grammar definition in `src/parser/bison_parser.y`.
2014-12-15 18:32:46 +01:00
2020-05-17 04:54:22 +02:00
If you're extending an existing statement, skip to the non-terminal definition for that statement. I.e. for an InsertStatement the non-terminal insert_statement.
2014-12-16 02:23:56 +01:00
2020-05-17 04:54:22 +02:00
If you're defining a new statement, you will need to define your type in the \%union directive `hsql::ExampleStatement example_stmt`. Next you need to associate this type with a non-terminal `\%type <example_stmt> example_statement`. Then you have to define the non-terminal `example_statement`. Look the other non-terminals for statements to figure out how.
2014-12-15 18:32:46 +01:00
## Implementing Tests
2016-02-27 16:58:51 +01:00
All test related files are in `test/`. Take a look to see how tests are implemented.
2014-12-15 18:32:46 +01:00