dal-ast-js 0.0.1-dev → 0.0.3-dev
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -7
- package/dist/index.cjs +11 -2
- package/dist/index.esm.js +11 -2
- package/docs/validation_planning +12 -0
- package/package.json +1 -1
- package/src/ArgsParser.js +3 -0
- package/src/DalAstGenerator.js +1 -0
- package/src/DesignValidator.js +8 -0
- package/src/Lexer.js +1 -1
- package/src/Parser.js +6 -1
- package/src/docs/commands.json +56 -0
- package/tests/Lexer.test.js +1 -1
- package/tests/designs/database_example/my_database.db +0 -0
- package/tests/designs/database_example/registered.py +30 -0
- package/tests/designs/database_example/reverse_name_persist.dal +51 -0
- package/tests/designs/database_example/synthesized.py +46 -0
- package/tests/output/ast.json +71 -429
- package/tests/output/test_tokens.json +802 -2442
- package/synthesizer/Synthesizer.py +0 -88
- package/synthesizer/asts/lib_manager_ast.json +0 -842
- package/synthesizer/dal_ast_synthesizer.py +0 -31
- package/synthesizer/docs/commands.json +0 -8
- package/synthesizer/getSynthesizedNode.py +0 -362
- package/synthesizer/helper.py +0 -13
- package/synthesizer/output/LoggingHelper.py +0 -57
- package/synthesizer/output/synthesized.py +0 -76
- package/synthesizer/output_helpers/LoggingHelper.py +0 -57
- package/synthesizer/output_helpers/readme.md +0 -3
- package/synthesizer/readme.md +0 -9
- package/tests/designs/test3.dal +0 -16
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import ast
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
from getSynthesizedNode import getSynthesizedNode
|
|
4
|
-
import shutil
|
|
5
|
-
|
|
6
|
-
class Synthesizer:
|
|
7
|
-
|
|
8
|
-
def __init__(self, dalAst):
|
|
9
|
-
self.dalAst = dalAst
|
|
10
|
-
self.pythonAst = ast.Module(
|
|
11
|
-
body=[],
|
|
12
|
-
type_ignores=[]
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
def run(self):
|
|
16
|
-
'''
|
|
17
|
-
Run the synthesizer
|
|
18
|
-
'''
|
|
19
|
-
# Process each node in the DAL ast.
|
|
20
|
-
for node in self.dalAst["body"]:
|
|
21
|
-
self.processTree(node, self.pythonAst, 0)
|
|
22
|
-
|
|
23
|
-
importNode = ast.parse("from LoggingHelper import semanticLogger").body[0]
|
|
24
|
-
self.pythonAst.body.insert(0, importNode)
|
|
25
|
-
|
|
26
|
-
self.writeToOutputFolder()
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def writeToOutputFolder(self):
|
|
30
|
-
'''
|
|
31
|
-
Writes the synthesized output to output folder and
|
|
32
|
-
also adds the logging helper.
|
|
33
|
-
|
|
34
|
-
If the output folder has files, clear it.
|
|
35
|
-
'''
|
|
36
|
-
outputFolder = Path(__file__).parent / "output"
|
|
37
|
-
|
|
38
|
-
# Make folder if it doesn't exist
|
|
39
|
-
outputFolder.mkdir(parents=True, exist_ok=True)
|
|
40
|
-
|
|
41
|
-
# Clear the output folder (assuming it existed)
|
|
42
|
-
for item in outputFolder.iterdir():
|
|
43
|
-
if item.is_dir():
|
|
44
|
-
shutil.rmtree(item)
|
|
45
|
-
else:
|
|
46
|
-
item.unlink()
|
|
47
|
-
|
|
48
|
-
# Write the synthesized output
|
|
49
|
-
outputFile = Path(__file__).parent / "output" / "synthesized.py"
|
|
50
|
-
with open(outputFile,"w+") as f:
|
|
51
|
-
f.write(ast.unparse(self.pythonAst))
|
|
52
|
-
|
|
53
|
-
# Copyt logging helper
|
|
54
|
-
src = Path(__file__).parent / "output_helpers" / "LoggingHelper.py"
|
|
55
|
-
dst = Path(__file__).parent / "output" / "LoggingHelper.py"
|
|
56
|
-
shutil.copy(src, dst)
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
def processTree(self, dalAstNode, pythonAstNode, indent):
|
|
60
|
-
'''
|
|
61
|
-
Process the tree node. If there is a body, process
|
|
62
|
-
each node in the body.
|
|
63
|
-
|
|
64
|
-
Writes the synthesized ast node to the ast tree.
|
|
65
|
-
'''
|
|
66
|
-
# self.printTree(indent, dalAstNode["type"])
|
|
67
|
-
astNodeBody = getSynthesizedNode(dalAstNode)
|
|
68
|
-
|
|
69
|
-
if astNodeBody is None:
|
|
70
|
-
if dalAstNode['type'] == "cmd":
|
|
71
|
-
type = dalAstNode['type'] + "," + dalAstNode['command']
|
|
72
|
-
else:
|
|
73
|
-
type = dalAstNode['type']
|
|
74
|
-
print(f"Unable to synthesize node of type {type}")
|
|
75
|
-
else:
|
|
76
|
-
ast.fix_missing_locations(astNodeBody)
|
|
77
|
-
pythonAstNode.body.append(astNodeBody)
|
|
78
|
-
|
|
79
|
-
if "body" in dalAstNode:
|
|
80
|
-
for node in dalAstNode["body"]:
|
|
81
|
-
self.processTree(node, astNodeBody, indent + 1)
|
|
82
|
-
|
|
83
|
-
def printTree(self, indent, value):
|
|
84
|
-
'''
|
|
85
|
-
Prints Tree with indentation for inspection.
|
|
86
|
-
'''
|
|
87
|
-
spaces = (indent * 4) * " "
|
|
88
|
-
print(f"{spaces}{value}")
|