Advertisement
Whistik

Untitled

Jul 12th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. class build():
  2.  
  3.     ALLOWED_TYPES = ['echo', 'print', 'var', '']
  4.     RECOGNIZED_TYPES = []
  5.     RECOGNIZED_TYPE_VALUES = []
  6.  
  7.     def __init__(self, FileName):
  8.         self.FileName = FileName
  9.         self.buildFromFile()
  10.  
  11.     def buildFromFile(self):
  12.         with open(self.FileName, 'r', encoding='utf-8') as FileDocument:
  13.             for i, DocumentLines in enumerate(FileDocument):
  14.                 DocumentLines = DocumentLines.lower()
  15.                 Line = DocumentLines.split('\n')
  16.  
  17.                 Type = Line[0].split(" ")
  18.                 if Type[0] in self.ALLOWED_TYPES and Type[0] != '':
  19.                     self.RECOGNIZED_TYPES.append({i: Type})
  20.                 elif Type[0] == '':
  21.                     pass
  22.                 else:
  23.                     print("Unrecognized type of '"+Type[0]+"' on line "+str((i+1))+", program terminated.")
  24.                     return
  25.  
  26.         self.CheckTypes()
  27.  
  28.     def Type_echo(self, TypeValue):
  29.         #[{'echo': "'aaaaa'"}, {'print': "'aaaaa'"}, {'var': "'a'"}]
  30.         print(TypeValue)
  31.  
  32.     def Type_print(self, TypeValue):
  33.         self.Typeecho(TypeValue)
  34.  
  35.     def Type_var(self, Variable):
  36.         # Variable structure: var NAME = 'VALUE';
  37.         pass
  38.  
  39.     def CheckTypes(self):
  40.         # echo 'Neco'
  41.         # print 'Neco'
  42.         # var neco = 'neco'
  43.         for i, Type in enumerate(self.RECOGNIZED_TYPES):
  44.             #tst = self.RECOGNIZED_TYPE_VALUES[i].get(Type)
  45.             #tst = str(self.RECOGNIZED_TYPE_VALUES[i]).split("'")
  46.             pass
  47.             '''
  48.             ['{', 'echo', ': "', 'aaaaa', '"}']
  49.             ['{', 'print', ': "', 'aaaaa', '"}']
  50.             ['{', 'var', ': "', 'a', '"}']
  51.             '''
  52.             #print(self.RECOGNIZED_TYPE_VALUES)
  53.            
  54.             #exec("self.Type_"+Type + '('+tst+')')
  55.  
  56. cls = build('test.txt')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement