Skip to content

Commit

Permalink
chore: Replace generate_grammar.py with generate-grammar.vsh (#204)
Browse files Browse the repository at this point in the history
Co-authored-by: ge <gechandev@gmail.com>
  • Loading branch information
gechandesu and gechandesu authored Dec 29, 2024
1 parent eaa590c commit 7043a23
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 38 deletions.
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

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.

0 comments on commit 7043a23

Please sign in to comment.