Skip to content

Commit

Permalink
Added SQL parser generation support/Refactored parser dir/fixed workf…
Browse files Browse the repository at this point in the history
…lows problems
  • Loading branch information
1NepuNep1 committed Jan 7, 2025
1 parent e47bbc1 commit 41a9b70
Show file tree
Hide file tree
Showing 28 changed files with 100,447 additions and 243 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/check-codegen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,19 @@ jobs:
go-version: ${{ matrix.go-version }}

- name: Build Docker image (ANTLR)
working-directory: parser/yql
working-directory: parser
run: |
make build-image
- name: Make clean
working-directory: parser/yql
working-directory: parser
run: |
make clean
- name: Generate (ANTLR)
working-directory: parser/yql
- name: Generate YQL & SQL Parser (ANTLR)
working-directory: parser
run: |
make generate
make all
- name: Check repository diff
run: |
Expand Down
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ issues:
- path: tests
linters:
- funlen
- path: parser/.*
linters:
- ALL
# Allow underscore and capital camel case for readability
# Examples: Type_PRIMITIVE_TYPE_ID_UNSPECIFIED, Ydb_Discovery_V1, _voidValue
- linters:
Expand Down
1 change: 1 addition & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ignore:
- trace
- testutil
- examples
- parser
18 changes: 14 additions & 4 deletions parser/yql/Dockerfile → parser/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ RUN apt-get update && apt-get install -y \
&& rm -rf /var/lib/apt/lists/*

ENV ANTLR_VERSION=4.13.2
ENV COMMIT_HASH=2876ba42c43c18664efd1fa3db856b7211ea4232

ENV ANTLR_VERSION=4.13.2
RUN curl -O https://www.antlr.org/download/antlr-${ANTLR_VERSION}-complete.jar
Expand All @@ -17,13 +18,22 @@ RUN echo "alias antlr='java -jar /antlr-${ANTLR_VERSION}-complete.jar'" >> ~/.ba

WORKDIR /workspace

RUN curl -L -o SQLv1Antlr4.g.in https://raw.githubusercontent.com/ydb-platform/ydb/main/yql/essentials/sql/v1/SQLv1Antlr4.g.in
RUN curl -L -o SQLv1Antlr4.g.in https://raw.githubusercontent.com/ydb-platform/ydb/${COMMIT_HASH}/yql/essentials/sql/v1/SQLv1Antlr4.g.in

RUN cp SQLv1Antlr4.g.in YQLv1Antlr4.g.in

RUN mv SQLv1Antlr4.g.in SQLv1Antlr4.g4
RUN mv YQLv1Antlr4.g.in YQLv1Antlr4.g4

RUN sed -i "s/grammar SQLv1Antlr4/grammar YQLv1Antlr4/g" YQLv1Antlr4.g4

#to fix
RUN sed -i "s/@GRAMMAR_STRING_CORE_SINGLE@/~('\\\'\' | '\\\\\\\\') | ('\\\\\\\\' .)/g" SQLv1Antlr4.g4 && \
sed -i "s/@GRAMMAR_STRING_CORE_DOUBLE@/~('\\\"\' | '\\\\\\\\') | ('\\\\\\\\' .)/g" SQLv1Antlr4.g4 && \
sed -i "s/@GRAMMAR_MULTILINE_COMMENT_CORE@/./g" SQLv1Antlr4.g4
RUN sed -i "s/@GRAMMAR_STRING_CORE_SINGLE@/~('\\\'\' | '\\\\\\\\') | ('\\\\\\\\' .)/g" YQLv1Antlr4.g4 && \
sed -i "s/@GRAMMAR_STRING_CORE_DOUBLE@/~('\\\"\' | '\\\\\\\\') | ('\\\\\\\\' .)/g" YQLv1Antlr4.g4 && \
sed -i "s/@GRAMMAR_MULTILINE_COMMENT_CORE@/./g" YQLv1Antlr4.g4

RUN sed -i "s/@GRAMMAR_STRING_CORE_SINGLE@/~'\\\\\'\' | ('\\\\\'\' '\\\\\'\')/g" SQLv1Antlr4.g4 && \
sed -i "s/@GRAMMAR_STRING_CORE_DOUBLE@/~'\\\"\' | ('\\\"\' '\\\"\')/g" SQLv1Antlr4.g4 && \
sed -i "s/@GRAMMAR_MULTILINE_COMMENT_CORE@/MULTILINE_COMMENT | ./g" SQLv1Antlr4.g4

CMD ["bash"]
47 changes: 47 additions & 0 deletions parser/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
IMAGE_NAME=yql-antlr-parser:latest
ANTLR_VERSION=4.13.2
CURRENT_DIR := $(shell pwd)

.PHONY: all
all: yql sql

.PHONY: yql
yql: build-image
docker run --rm -v "$(CURRENT_DIR)/yql":/workspace/yql $(IMAGE_NAME) \
java -jar /antlr-${ANTLR_VERSION}-complete.jar -Dlanguage=Go -package yql -o yql YQLv1Antlr4.g4

.PHONY: sql
sql: build-image
docker run --rm -v "$(CURRENT_DIR)/sql":/workspace/sql $(IMAGE_NAME) \
java -jar /antlr-${ANTLR_VERSION}-complete.jar -Dlanguage=Go -package sql -o sql SQLv1Antlr4.g4


.PHONY: build-image
build-image:
docker build -t $(IMAGE_NAME) .


.PHONY: clean_yql
clean_yql:
rm -rf yql/*.go
rm -rf yql/*.interp
rm -rf yql/*.tokens

.PHONY: clean_sql
clean_sql:
rm -rf sql/*.go
rm -rf sql/*.interp
rm -rf sql/*.tokens

.PHONY: clean
clean: clean_yql clean_sql


.PHONY: regenerate_yql
regenerate_yql: clean_yql yql

.PHONY: regenerate_sql
regenerate_sql: clean_sql sql

.PHONY: regenerate
regenerate: regenerate_yql regenerate_sql
81 changes: 81 additions & 0 deletions parser/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# YQL ANTLR Parser Generator

This project provides code generation of YQL and SQL parsers using ANTLR4.

---

## Makefile Targets

### General Targets

- **`all`**
Generates both YQL and SQL parsers.
```bash
make all
```

- **`build-image`**
Builds the Docker image required for parser generation.
```bash
make build-image
```

- **`clean`**
Cleans all generated files for both YQL and SQL.
```bash
make clean
```

- **`regenerate`**
Cleans and regenerates all parser files (YQL and SQL).
```bash
make regenerate
```
### YQL Parser Targets

- **`yql`**
Generates the YQL parser files.
```bash
make yql
```

- **`clean_yql`**
Removes all generated YQL parser files (`*.go`, `*.interp`, `*.tokens`).
```bash
make clean_yql
```

- **`regenerate_yql`**
Cleans and regenerates the YQL parser files.
```bash
make regenerate_yql
```

### SQL Parser Targets

- **`sql`**
Generates the SQL parser files.
```bash
make sql
```

- **`clean_sql`**
Removes all generated SQL parser files (`*.go`, `*.interp`, `*.tokens`).
```bash
make clean_sql
```

- **`regenerate_sql`**
Cleans and regenerates the SQL parser files.
```bash
make regenerate_sql
```

---

## Project Structure

- **`yql/`**: Directory for YQL parser files.
- **`sql/`**: Directory for SQL parser files.
- **`Dockerfile`**: Dockerfile for the parser generation environment.
- **`Makefile`**: Contains all automation commands.
8 changes: 8 additions & 0 deletions parser/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module ydb-go-sdk/parser

go 1.23.4

require (
github.com/antlr4-go/antlr/v4 v4.13.1
golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect
)
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 41a9b70

Please sign in to comment.