-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrun.py
29 lines (25 loc) · 908 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
class ExecuteScript(object):
def __init__(self,
filename=None,
from_file=True,
content=None,
error=None,
lexer=None,
parser=None):
self.filename = filename
self.from_file = from_file
self.content = content
self.error = error
self.lexer = lexer
self.parser = parser
if self.from_file:
if not os.path.isfile(self.filename):
if self.error:
self.error(f'{self.filename} is not a file')
with open(self.filename, 'r') as file_content_reader:
self.content = file_content_reader.read()
self.execute_script()
def execute_script(self):
tokens = self.lexer.lex(self.content)
parser = self.parser.parse(tokens)