@@ -129,8 +129,35 @@ def class_definition(f):
129129
130130
131131def process_if (py_script ):
132- # todo process if statements (remove brackets and add colon)
133- pass
132+ php_file = fileinput .FileInput (py_script , inplace = True )
133+ for line in php_file :
134+ reg = r'(.*)if(.*)\((.*)\)(.*)\{$'
135+ match = re .match (reg , line )
136+ if match :
137+ groups = match .groups ()
138+ if_indent = groups [0 ]
139+ if_line = if_indent + 'if ' + groups [2 ] + ':'
140+ print (if_line )
141+ else :
142+ print (line ),
143+
144+ php_file .close ()
145+
146+
147+ def process_else (py_script ):
148+ php_file = fileinput .FileInput (py_script , inplace = True )
149+ for line in php_file :
150+ reg = r'(.*)\}(.*)else(.*)(.*)\{$'
151+ match = re .match (reg , line )
152+ if match :
153+ groups = match .groups ()
154+ else_indent = groups [0 ]
155+ else_line = else_indent + 'else :'
156+ print (else_line )
157+ else :
158+ print (line ),
159+
160+ php_file .close ()
134161
135162
136163def convert2python (php_script , py_script , overwrite ):
@@ -155,6 +182,12 @@ def convert2python(php_script, py_script, overwrite):
155182 logger .info ('# convert :: to .' )
156183 replace (py_script , '::' , '.' )
157184
185+ logger .info ('# Process if statements' )
186+ process_if (py_script )
187+
188+ logger .info ('# Process else statements' )
189+ process_else (py_script )
190+
158191 logger .info ('# delete all }' )
159192 logger .info ('# delete namespace|require_once|include_once' )
160193 remove_lines_bound (py_script , "namespace" , ";" )
@@ -181,9 +214,6 @@ def convert2python(php_script, py_script, overwrite):
181214 logger .info ('# convert new to \' \' ' )
182215 replace (py_script , 'new ' , '' )
183216
184- logger .info ('# Process if statements' )
185- process_if (py_script )
186-
187217 logger .info (("Converted: %s. to: %s. { Go on, Proof Check :) }" % (php_script , py_script )))
188218
189219
0 commit comments