Skip to content

Commit c005fa7

Browse files
changes
1 parent d57302e commit c005fa7

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from .Fragment import Fragment
2+
from utils.flags import *
3+
from utils.CustomLogging import CustomLogging
4+
from python_compiler.engines.utils.types import get_python_type_str, ANY
5+
6+
def get_conditional_condition(fragment) -> str:
7+
if not (condition := fragment.get(ATTRIBUTE_CONDITIONAL_CONDITION)):
8+
CustomLogging.critical(f"Fragment type conditional '{ATTRIBUTE_CONDITIONAL_CONDITION}' attribute does not exist")
9+
return condition
10+
11+
def get_conditional_code(fragment) -> list:
12+
if not (code := fragment.get(ATTRIBUTE_CONDITIONAL_CODE)):
13+
CustomLogging.critical(f"Fragment type conditional '{ATTRIBUTE_CONDITIONAL_CODE}' attribute does not exist")
14+
return code
15+
class Conditional(Fragment):
16+
condition:str
17+
code:list
18+
def __init__(self, blueprint, *args, **kwargs) -> None:
19+
super().__init__( blueprint, *args, **kwargs)
20+
self.condition = get_conditional_condition(blueprint)
21+
self.code = get_conditional_code(blueprint)
22+
def code_lines_compile(self) -> list:
23+
code_build_lines = []
24+
for line in self.code:
25+
code_build_lines.append(TAB*(self.level+1)+self.general_compile(line))
26+
return code_build_lines
27+
def compile(self)->str:
28+
fragment_lines = []
29+
fragment_lines.append(f"if {self.condition}:")
30+
fragment_lines.extend(self.code_lines_compile())
31+
fragment_build = "\n".join(fragment_lines)
32+
33+
return fragment_build
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
from .Fragment import Fragment
2+
from utils.flags import *
3+
from utils.CustomLogging import CustomLogging
4+
from python_compiler.engines.utils.types import get_python_type_str, ANY
5+
6+
def get_function_name(fragment) -> str:
7+
if not (function_name := fragment.get(ATTRIBUTE_FUNCTION_CALL_NAME)):
8+
CustomLogging.critical(f"Fragment type function_call '{ATTRIBUTE_FUNCTION_CALL_NAME}' attribute does not exist")
9+
return function_name
10+
11+
def get_function_args(fragment) -> dict:
12+
if not (function_args := fragment.get(ATTRIBUTE_FUNCTION_ARGS)):
13+
function_args = {}
14+
return function_args
15+
16+
def get_function_kwargs(fragment) -> dict:
17+
if not (function_kwargs := fragment.get(ATTRIBUTE_FUNCTION_KWARGS)):
18+
function_kwargs = {}
19+
return function_kwargs
20+
21+
class FunctionCall(Fragment):
22+
name:str
23+
args:dict
24+
kwargs:dict
25+
def __init__(self, blueprint, *args, **kwargs) -> None:
26+
super().__init__( blueprint, *args, **kwargs)
27+
self.name = get_function_name(blueprint)
28+
self.args = get_function_args(blueprint)
29+
self.kwargs = get_function_kwargs(blueprint)
30+
def inputs_compile(self) -> str:
31+
inputs = []
32+
if self.args:
33+
inputs = self.args
34+
35+
if self.kwargs:
36+
inputs.extend([ f"{x}:{self.kwargs[x]}" for x in self.kwargs])
37+
38+
inputs_build = ", ".join(inputs)
39+
return inputs_build
40+
def compile(self)->str:
41+
fragment_build = f"{self.name}({self.inputs_compile()})"
42+
43+
return fragment_build

0 commit comments

Comments
 (0)