11import os , time
2+
3+ '''
4+ import SyntaxGrabber
5+ from ErrorHandler import classErrorHandler
6+ '''
7+
28from assets import SyntaxGrabber
39from assets .ErrorHandler import classErrorHandler
10+ from assets .successHandler import classSuccessHandler
11+ from assets .initParser import initParserClass
412
513PureCode = {}
614Count = 0
715CurrentSyntax = ""
816lineCount = 0
917currentLineNumber = 0
1018filePath = ""
19+ syntaxFound = False
1120
1221class Parser :
1322 def __init__ (self ):
@@ -72,7 +81,7 @@ def DotCheck(self , name):
7281
7382 def SpaceSet (self , Values ):
7483 global Count
75-
84+
7685 if type (Values ) == list :
7786 for Argument in Values :
7887 if "^" in Argument :
@@ -163,7 +172,7 @@ def VAR(self , LineOfCode):
163172 if "," in Function :
164173 Values = Function .split ("," )
165174 Values = self .SpaceSet (Values )
166-
175+
167176 for VarsStuff in Values :
168177 lastValue = VarsStuff
169178
@@ -215,7 +224,7 @@ def IF(self , LineOfCode):
215224 if "," in Condition :
216225 Values = Condition .split ("," )
217226 Values = self .SpaceSet (Values )
218-
227+
219228 if len (Values ) < 3 or len (Values ) > 3 :
220229 self .errorCaller (
221230 LineOfCode = LineOfCode ,
@@ -257,8 +266,26 @@ def TEST(self , LineOfCode):
257266
258267 return ""
259268
269+ def INIT (self , LineOfCode ):
270+ global CurrentSyntax
271+
272+ initParserFunctions = globals ()['initParserClass' ]()
273+ initParser = getattr (initParserFunctions , 'initParser' )
274+
275+ initVariables = initParser (CurrentSyntax = CurrentSyntax )
276+ for Key ,Value in initVariables .items ():
277+ PureCode [Key ] = Value
278+
279+ return ''
280+
260281def Main (File , Mode , Output ):
261- global CurrentSyntax , currentLineNumber , filePath
282+ global CurrentSyntax , currentLineNumber , filePath , syntaxFound
283+
284+ errorHandler = globals ()['classErrorHandler' ]()
285+ showErrorMessage = getattr (errorHandler , 'showErrorMessage' )
286+
287+ successHandler = globals ()['classSuccessHandler' ]()
288+ showSuccessMessage = getattr (successHandler , 'showSuccessMessage' )
262289
263290 Content = open (File , 'r' )
264291 Syntax = SyntaxGrabber .GrapSyntaxKeys ()
@@ -272,25 +299,27 @@ def Main(File, Mode , Output):
272299 if ";" in CodeLine :
273300 if "<'" and "'>" in CodeLine : pass
274301 else : CodeLine = CodeLine .replace (';' , '\n ' )
275-
302+
276303 for SingleSyntax in Syntax :
277304 Limit = len (SingleSyntax )
278305
279306 if '\n ' not in CodeLine :
280307 if CodeLine .replace (' ' , '' )[:Limit ].upper () == SingleSyntax :
308+ syntaxFound = True
281309 CurrentSyntax = SingleSyntax
282310 Call = globals ()['Parser' ]()
283311 Function = getattr (Call , SingleSyntax )
284312 Code += Function (CodeLine )
285313 elif CodeLine .replace (' ' , '' )[:1 ] == Comment :
286- pass
314+ syntaxFound = True
287315 else :
288316 pass
289317 else :
290318 Codes = CodeLine .split ('\n ' )
291319 for SomeCode in Codes :
292320 if SomeCode .replace (' ' , '' )[:Limit ].upper () == SingleSyntax :
293321 CurrentSyntax = SingleSyntax
322+ syntaxFound = True
294323 Call = globals ()['Parser' ]()
295324 Function = getattr (Call , SingleSyntax )
296325 Code += Function (SomeCode )
@@ -303,16 +332,25 @@ def Main(File, Mode , Output):
303332 print (Code )
304333 elif Mode .lower ().replace (' ' , '' ) == "exec" or Mode .lower ().replace (' ' , '' ) == "execute" :
305334 startTime = time .process_time ()
306- exec (Code )
335+
336+ try :
337+ exec (Code )
338+ except Exception as e :
339+ showErrorMessage (Message = f"[<[Python Error]>]: { str (e )} " )
340+ return None
341+
307342 endTime = time .process_time ()
308- print (f"Code Execution Done in { endTime - startTime } Second/s." )
343+ realTime = endTime - startTime
344+
345+ if int (realTime ) < 1 : print ("Code Execution Done in Less Than 1 Second." )
346+ else : print (f"Code Execution Done in { int (realTime )} Second/s." )
309347 elif Mode .lower ().replace (' ' , '' ) == "compile" :
310348 CurrentPath = os .getcwd (); CurrentPath = CurrentPath .split ('\\ ' )
311349 FullPath = '/' .join (CurrentPath ); FullPath += f"/compiled/{ Output } "
312-
350+
313351 with open (FullPath , 'w' ) as OutputFile :
314352 OutputFile .write (Code ); OutputFile .close ()
315353
316- print ( f"The Compiled Code Has Been Saved On: { FullPath } " )
354+ showSuccessMessage ( Message = f"The Compiled Code Has Been Saved On: { FullPath } " )
317355 else :
318- print ( f"The Mode You Selected Doesn't Exists: { Mode } \n Modes: show, exec, execute, compile " )
356+ showErrorMessage ( Message = f"The Mode You Selected Doesn't Exists: { Mode } " )
0 commit comments