Skip to content

Commit c14228c

Browse files
authored
Create initParser.py
1 parent 080f528 commit c14228c

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

assets/initParser.py

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
from os import path
2+
3+
'''
4+
from Parser import Parser
5+
from ErrorHandler import classErrorHandler
6+
'''
7+
8+
'''
9+
from assets.Parser import Parser
10+
'''
11+
12+
13+
from assets.ErrorHandler import classErrorHandler
14+
15+
'''
16+
__INIT__ has been created for defining global variables only
17+
it can't be used to write your own easy code into it
18+
19+
you can use it to store global static variables and use it from your easy code
20+
to call __INIT__ from your easy code you can use `INIT` key on your code
21+
22+
any variables has been defined before with `DEFINE` key then defined again with __INIT__
23+
will be overritten in some cases.
24+
25+
the error messages are getting handled using the pre-made error handler on the assets.
26+
the error handler gonna be used for all functions.
27+
'''
28+
29+
class initParserClass:
30+
def __init__(self):
31+
self.initPaths = ["__INIT__.easy" , "__INIT__"]
32+
self.initExist = False
33+
self.initFile = ""
34+
self.initCode = {}
35+
36+
def StartsSpaceDel(self , LineOfCode):
37+
CurrentSyntax = self.CurrentSyntax
38+
39+
CodeWithoutKey = LineOfCode.replace(CurrentSyntax , '' , 1)
40+
for Character in CodeWithoutKey:
41+
if Character == " ": CodeWithoutKey = CodeWithoutKey[1:]
42+
else: break
43+
44+
return CodeWithoutKey
45+
46+
def EndsSpaceDel(self , LineOfCode):
47+
CurrentSyntax = self.CurrentSyntax
48+
ReversedString = LineOfCode[::-1]
49+
50+
for Character in ReversedString:
51+
if Character == " ": LineOfCode = LineOfCode[:-1]
52+
else: break
53+
54+
return LineOfCode
55+
56+
def externalSpaceFilter(self , codeList):
57+
errorHandler = globals()['classErrorHandler']()
58+
showErrorMessage = getattr(errorHandler , 'showErrorMessage')
59+
60+
if len(codeList) != 2:
61+
showErrorMessage(Message="You're using multiple values on a single variable. only one `=` is allowed.")
62+
exit()
63+
else:
64+
# Start parsing the __INIT__ variables
65+
firstItem = self.StartsSpaceDel(LineOfCode=codeList[0])
66+
firstItem = self.EndsSpaceDel(LineOfCode=firstItem)
67+
68+
secondItem = self.StartsSpaceDel(LineOfCode=codeList[1])
69+
secondItem = self.EndsSpaceDel(LineOfCode=secondItem)
70+
71+
return firstItem , secondItem
72+
73+
def initValidator(self):
74+
global classErrorHandler
75+
76+
for singlePath in self.initPaths:
77+
if path.exists(singlePath):
78+
if not self.initExist:
79+
self.initExist = True
80+
self.initFile = singlePath
81+
else:
82+
functions = globals()['classErrorHandler']()
83+
errorMessage = getattr(functions , 'showErrorMessage')
84+
errorMessage(Message="Multiple __INIT__ Files Has Been Detected. Only One __INIT__ is Allowed")
85+
return False
86+
87+
self.initExist = False
88+
return True
89+
90+
def initParser(self , CurrentSyntax):
91+
self.CurrentSyntax = CurrentSyntax
92+
if self.initValidator():
93+
initContent = open(self.initFile , 'r')
94+
95+
for singleLine in initContent:
96+
singleLine = singleLine.rstrip('\n')
97+
codeList = singleLine.split('=')
98+
Key , Value = self.externalSpaceFilter(codeList=codeList)
99+
self.initCode[Key] = Value
100+
101+
return self.initCode
102+
else:
103+
exit()
104+
105+
'''
106+
if __name__ == '__main__':
107+
functions = globals()['initParserClass']()
108+
initParser = getattr(functions , 'initParser')
109+
initParser()
110+
'''

0 commit comments

Comments
 (0)