Skip to content

Commit

Permalink
Replace the version on the target index_files rather instead of appen…
Browse files Browse the repository at this point in the history
…ding.
  • Loading branch information
surister committed May 29, 2024
1 parent 054d30a commit 96c7bef
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions cratedb_sqlparse_js/cratedb_sqlparse/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
import {sqlparse} from "./parser.js";
export {sqlparse};
export const __cratedb_version__ = "5.6.4"
2 changes: 2 additions & 0 deletions cratedb_sqlparse_py/cratedb_sqlparse/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from .parser import ParsingException, sqlparse

__all__ = ["sqlparse", "ParsingException"]
__cratedb_version__ = "5.6.4"

19 changes: 16 additions & 3 deletions setup_grammar.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import subprocess
import sys
import re
from enum import Enum
from pathlib import Path

Expand Down Expand Up @@ -137,9 +138,18 @@ def set_version(target: Antlr4Target, version: str):
index_file = 'index.js'
variable = 'export const __cratedb_version__'

# FIXME: Need to apply "replace" instead of "append"?
with open(target_path / index_file, "a") as f:
f.write(f"{variable} = {version}\n")
with open(target_path / index_file, "r+") as f:
content = f.read()

# Removes the current content on disk.
f.seek(0)
f.truncate()

updated_content = re.sub(f'({variable} = )"(.*)"', r'\1' + version, content)

f.write(updated_content)

logger.info(f'Updated {variable} to {version} in {index_file}')


if __name__ == '__main__':
Expand All @@ -150,14 +160,17 @@ def set_version(target: Antlr4Target, version: str):
TODO: Improve efficiency by generating runtime parser for all implemented languages at once.
"""
setup_logging()

input_target = sys.argv[1]
version = '5.6.4'

if input_target.startswith("py"):
target = Antlr4Target.python
elif input_target.startswith("js") or input_target.startswith("java"):
target = Antlr4Target.js
else:
raise NotImplementedError(f"Parser generator for target {input_target} not implemented")

download_cratedb_grammar(version)
compile_grammar(target)
patch_lexer(target)
Expand Down

0 comments on commit 96c7bef

Please sign in to comment.