Skip to content

Commit 8c91c6c

Browse files
authored
Merge 01178ac into 14708a4
2 parents 14708a4 + 01178ac commit 8c91c6c

File tree

6 files changed

+72
-4
lines changed

6 files changed

+72
-4
lines changed

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "vba_precompiler"
7-
version = "0.0.1"
7+
version = "0.0.2"
88
authors = [
99
{ name="Kevin Nowaczyk", email="beakerboy99@yahoo.com" },
1010
]
@@ -21,6 +21,7 @@ dependencies = [
2121
'antlr4-tools',
2222
'antlr4_vba',
2323
'python-dateutil',
24+
'vba-stdlib @ git+https://github.com/Beakerboy/vbaStdLib@dev'
2425
]
2526
[project.optional-dependencies]
2627
tests = [

src/vba_precompiler/__main__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import argparse
22
import sys
3+
from vba_stdlib.literal_factory import literal_from_string
34
from pathlib import Path
45
from vba_precompiler.compiler import Compiler
56

@@ -8,6 +9,8 @@ def main() -> None:
89
parser = argparse.ArgumentParser()
910
parser.add_argument("-s", "--system", default="Win16",
1011
help="Mac, Win16, Win32, or Win64")
12+
parser.add_argument("-D", "--define", default="",
13+
help="Define an enviromnet variable")
1114
parser.add_argument("-v", "--version", default="6",
1215
help="VBA version, 6 or 7")
1316
parser.add_argument("-o", "--output", default="./build",
@@ -41,9 +44,17 @@ def main() -> None:
4144
vba7 = True
4245
else:
4346
raise Exception("VBA Version Unsupported: " + args.version)
44-
4547
env = {"WIN16": win16, "WIN32": win32, "WIN64": win64,
4648
"MAC": mac, "VBA6": vba6, "VBA7": vba7, "MAC_OFFICE_VERSION": 0}
49+
if args.define != "":
50+
params = args.define.split(',')
51+
for name_value in params:
52+
pair = name_value.split("=")
53+
key = pair[0].upper()
54+
value = pair[1]
55+
if value[-1:1] == '""':
56+
value = value[1:-1]
57+
env[key] = literal_from_string(value)
4758
compiler = Compiler(env)
4859
Path(args.output).mkdir(parents=True, exist_ok=True)
4960
num_errors = 0

src/vba_precompiler/compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111

1212
class Compiler:
1313
# class default constructor
14-
def __init__(self: T, environment: dict) -> None:
15-
self.environment = environment
14+
def __init__(self: T, env: dict) -> None:
15+
self.environment = env
1616

1717
def compile(self: T, path: str) -> str:
1818
if Path(path).exists():

tests/Functional/test_main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,30 @@ def test_date_literal(mocker: MockerFixture) -> None:
341341
assert_files_identical(expected_output_file, target_output)
342342

343343

344+
def test_define(mocker: MockerFixture) -> None:
345+
"""
346+
Test that an the arithmetic operators work as expected.
347+
"""
348+
input_path = "tests/files/project17"
349+
file_name = "define.bas"
350+
args = ["IntTest=42", "FloatTest=3.1415926535",
351+
"BoolTest=True", 'StringTest="Yes"',
352+
"DateTest=#Jan/1/1999#"]
353+
arg_string = ",".join(args)
354+
mocker.patch(
355+
"sys.argv",
356+
[
357+
"vba_precompiler.py",
358+
'-D' + arg_string,
359+
input_path,
360+
],
361+
)
362+
main()
363+
expected_output_file = "./build/" + file_name
364+
target_output = "./tests/files/build/" + file_name
365+
assert_files_identical(expected_output_file, target_output)
366+
367+
344368
def assert_files_identical(new_file: str, target_output: str) -> bool:
345369
# if they are the same, just make the assertion
346370
# if not, raise an exception with details.

tests/files/build/define.bas

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Attribute VB_Name = "Define"
2+
'#if StringTest = "Yes"
3+
foo = 1
4+
'#endif
5+
'#if IntTest = 42
6+
foo = 1
7+
'#endif
8+
'#if BoolTest = True
9+
foo = 1
10+
'#endif
11+
'#if FloatTest = 3.1415926535
12+
foo = 1
13+
'#endif
14+
'#if DateTest = #01 Jan 1999#
15+
foo = 1
16+
'#endif

tests/files/project17/define.bas

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Attribute VB_Name = "Define"
2+
#if StringTest = "Yes"
3+
foo = 1
4+
#endif
5+
#if IntTest = 42
6+
foo = 1
7+
#endif
8+
#if BoolTest = True
9+
foo = 1
10+
#endif
11+
#if FloatTest = 3.1415926535
12+
foo = 1
13+
#endif
14+
#if DateTest = #01 Jan 1999#
15+
foo = 1
16+
#endif

0 commit comments

Comments
 (0)