Skip to content

Commit d57302e

Browse files
python conditional and function call compilers
1 parent be2301f commit d57302e

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

blueprints/examples/calculator/v2/services/processing/operations/sum.code.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"code": [
3333
{
3434
"type": "function_call",
35+
"function":"print",
3536
"args": ["result"]
3637
}
3738
]

compiler/python_compiler/engines/py3_8/Compiler.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
from .get_fragment_class import get_fragment_class
33

44

5-
def compile(blueprint:dict)->str:
6-
build = get_fragment_class(blueprint, compile)
5+
def compile(blueprint:dict, *, level = 0)->str:
6+
build = get_fragment_class(blueprint, compile, level=level)
77
return build.compile()
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
class Fragment:
22
blueprint:dict
33
general_compile=None#:function
4-
def __init__(self, blueprint, *, compile) -> None:
4+
level=0
5+
def __init__(self, blueprint, *, compile, level=0) -> None:
56
self.general_compile = compile
67
self.blueprint = blueprint
8+
self.level = level
79
def compile(self)->str:
810
fragment_build = self.blueprint.get("type","")
911
return fragment_build

compiler/python_compiler/engines/py3_8/Function.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
def get_function_name(fragment) -> str:
88
if not (function_name := fragment.get(ATTRIBUTE_FUNCTION_NAME)):
9-
CustomLogging.critical(f"Fragment type functions 'name' attribute does not exists")
9+
CustomLogging.critical(f"Fragment type functions 'name' attribute does not exist")
1010
return function_name
1111

1212
def get_function_args(fragment) -> dict:
@@ -50,7 +50,7 @@ def inputs_compile(self) -> str:
5050
if self.kwargs:
5151
function_kwargs = FunctionArgs(self.kwargs, compile=self.general_compile)
5252
if self.args:
53-
inputs_build += ","
53+
inputs_build += "," # TODO: disguisting but effective
5454
inputs_build += f" *, {function_kwargs.compile()}"
5555
return inputs_build
5656
def outputs_compile(self) -> str:
@@ -63,7 +63,7 @@ def outputs_compile(self) -> str:
6363
def code_lines_compile(self) -> list:
6464
code_build_lines = []
6565
for line in self.code:
66-
code_build_lines.append(TAB+self.general_compile(line))
66+
code_build_lines.append(TAB*(self.level+1)+self.general_compile(line, level=self.level+1))
6767
return code_build_lines
6868
def compile(self)->str:
6969
fragment_lines = []

compiler/python_compiler/engines/py3_8/Variable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
def get_variable_name(fragment) -> str:
2525
if not (variable_name := fragment.get(ATTRIBUTE_VARIABLE_NAME)):
26-
CustomLogging.critical(f"Fragment type variable '{ATTRIBUTE_VARIABLE_NAME}' attribute does not exists")
26+
CustomLogging.critical(f"Fragment type variable '{ATTRIBUTE_VARIABLE_NAME}' attribute does not exist")
2727
return variable_name
2828

2929
def get_variable_type(fragment) -> str:
@@ -40,7 +40,7 @@ def get_variable_assign_operator(fragment) -> str:
4040

4141
def get_variable_expression(fragment) -> str:
4242
if not (variable_expression := fragment.get(ATTRIBUTE_VARIABLE_EXPRESSION)):
43-
CustomLogging.critical(f"Fragment type variable '{ATTRIBUTE_VARIABLE_EXPRESSION}' attribute does not exists")
43+
CustomLogging.critical(f"Fragment type variable '{ATTRIBUTE_VARIABLE_EXPRESSION}' attribute does not exist")
4444
return variable_expression
4545

4646

compiler/python_compiler/engines/py3_8/get_fragment_class.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
"return":Return
1919
}
2020

21-
def get_fragment_class(blueprint, compile):
21+
def get_fragment_class(blueprint, compile, *, level=0):
2222
if fragment_type := blueprint.get(ATTRIBUTE_FRAGMENT_TYPE):
2323
if fragment_class := FRAGMENT_TYPES[fragment_type]:
24-
return fragment_class(blueprint, compile=compile)
24+
return fragment_class(blueprint, compile=compile, level=level)
2525
else:
26-
CustomLogging.error(f"Fragment type {fragment_type} does not exists")
26+
CustomLogging.error(f"Fragment type {fragment_type} does not exist")
2727
else:
2828
CustomLogging.error(f"Flag {ATTRIBUTE_FRAGMENT_TYPE} not defined in blueprint")

compiler/utils/flags.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,12 @@ def to_flag(text:str):
2828

2929
ATTRIBUTE_FUNCTION_RETURN_ARGS = "args"
3030

31+
ATTRIBUTE_FUNCTION_CALL_NAME = "function"
3132

3233
ATTRIBUTE_VARIABLE_NAME = "name"
3334
ATTRIBUTE_VARIABLE_TYPE = "variable_type"
3435
ATTRIBUTE_VARIABLE_EXPRESSION = "expression"
35-
ATTRIBUTE_VARIABLE_ASSIGN_OPERATOR = "assign_operator"
36+
ATTRIBUTE_VARIABLE_ASSIGN_OPERATOR = "assign_operator"
37+
38+
ATTRIBUTE_CONDITIONAL_CONDITION = "condition"
39+
ATTRIBUTE_CONDITIONAL_CODE = "code"

0 commit comments

Comments
 (0)