Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace generate_grammar.py by generate-grammar.vsh #204

Merged
merged 3 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ vsql-server
*.vsql
.vscode
.vlang_tmp_build/
grammar.bnf
vsql/grammar.v
scripts/generate-v-client-library-docs
scripts/generate-grammar
y.output
vsql/y.v
vsql/y.y
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ clean-docs:
# Grammar

vsql/y.y:
python3 scripts/generate_grammar.py
./scripts/generate-grammar.vsh

vsql/y.v: vsql/y.y
v run scripts/vyacc.v -o vsql/y.v vsql/y.y
Expand Down
9 changes: 0 additions & 9 deletions docs/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,6 @@ available and these will be close enough to use as a reference:
1. `SQL 2016 Foundation Grammar (BNF) <https://jakewheat.github.io/sql-overview/sql-2016-foundation-grammar.html>`_
2. `SQL 1999 <https://crate.io/docs/sql-99/en/latest//>`_

Wait! You said this is pure V but I see a Python file?
------------------------------------------------------

The python file ``generate-grammar.py`` is used to convert the BNF grammar into
V code that makes up the parser. The result file ``grammar.v`` is committed so
there is no need to use python to compile and otherwise work on vsql unless you
need to change the grammar. However, if you would like to covert this script to
V, I'd be happy to have your help!

Why is there no `NOW()` function?
---------------------------------

Expand Down
40 changes: 40 additions & 0 deletions scripts/generate-grammar.vsh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env -S v
gechandesu marked this conversation as resolved.
Show resolved Hide resolved

path := abs_path('vsql')
output_filename := join_path_single(path, 'y.y')
files := glob(join_path_single(path, '*.y')) or { [] }

mut top := ''
mut middle := ''
mut bottom := ''

for file_path in files {
if is_dir(file_path) {
continue
}
content := read_file(file_path) or {
eprintln('error: unable to open file ${file_path}: ${err}')
exit(1)
}
parts := content.split('%%')
if parts.len != 3 {
eprintln('${file_path}: wrong number of parts (${parts.len})')
exit(1)
}
top += parts[0]
middle += parts[1]
bottom += parts[2]
}

mut output := open_file(output_filename, 'w') or {
eprintln('error: unable to open file to write')
exit(1)
}

output.writeln(top.trim_space())!
output.writeln('%%')!
output.writeln(middle.trim_space())!
output.writeln('%%')!
output.write_string(bottom.trim_space())!
output.flush()
output.close()
26 changes: 0 additions & 26 deletions scripts/generate_grammar.py

This file was deleted.

Loading