@@ -44,35 +44,15 @@ class ASTNode:
4444 children = []
4545 arguments = {}
4646
47- func get_code_block () -> String :
48- var code_block : String = data .code_template # get multiline code_template from block definition
49-
50- # insert args
51-
52- # check if args match an overload in the resource
53-
54- for arg_name in arguments :
55- # Use parentheses to be safe
56- var argument = arguments [arg_name ]
57- var code_string : String
58- var raw_string : String
59- if argument is ASTValueNode :
60- code_string = argument .get_code ()
61- raw_string = code_string
62- else :
63- code_string = BlockAST .raw_input_to_code_string (argument )
64- raw_string = str (argument )
65-
66- code_block = code_block .replace ("{{ %s }} " % arg_name , raw_string )
67- code_block = code_block .replace ("{%s }" % arg_name , code_string )
68-
47+ func _get_code_block () -> String :
48+ var code_block : String = BlockAST .format_code_template (data .code_template , arguments )
6949 return IDHandler .make_unique (code_block )
7050
7151 func get_code (depth : int ) -> String :
7252 var code : String = ""
7353
7454 # append code block
75- var code_block := get_code_block ()
55+ var code_block := _get_code_block ()
7656 code_block = code_block .indent ("\t " .repeat (depth ))
7757
7858 code += code_block + "\n "
@@ -95,25 +75,7 @@ class ASTValueNode:
9575 arguments = {}
9676
9777 func get_code () -> String :
98- var code : String = data .code_template # get code_template from block definition
99-
100- # check if args match an overload in the resource
101-
102- for arg_name in arguments :
103- # Use parentheses to be safe
104- var argument = arguments [arg_name ]
105- var code_string : String
106- var raw_string : String
107- if argument is ASTValueNode :
108- code_string = argument .get_code ()
109- raw_string = code_string
110- else :
111- code_string = BlockAST .raw_input_to_code_string (argument )
112- raw_string = str (argument )
113-
114- code = code .replace ("{{ %s }} " % arg_name , raw_string )
115- code = code .replace ("{%s }" % arg_name , code_string )
116-
78+ var code : String = BlockAST .format_code_template (data .code_template , arguments )
11779 return IDHandler .make_unique ("(%s )" % code )
11880
11981
@@ -135,6 +97,26 @@ func to_string_recursive(node: ASTNode, depth: int) -> String:
13597 return string
13698
13799
100+ static func format_code_template (code_template : String , arguments : Dictionary ) -> String :
101+ for argument_name in arguments :
102+ # Use parentheses to be safe
103+ var argument_value : Variant = arguments [argument_name ]
104+ var code_string : String
105+ var raw_string : String
106+
107+ if argument_value is ASTValueNode :
108+ code_string = argument_value .get_code ()
109+ raw_string = code_string
110+ else :
111+ code_string = BlockAST .raw_input_to_code_string (argument_value )
112+ raw_string = str (argument_value )
113+
114+ code_template = code_template .replace ("{{ %s }} " % argument_name , raw_string )
115+ code_template = code_template .replace ("{%s }" % argument_name , code_string )
116+
117+ return code_template
118+
119+
138120static func raw_input_to_code_string (input ) -> String :
139121 match typeof (input ):
140122 TYPE_STRING :
0 commit comments