1
0

Add files via upload

This commit is contained in:
Deven Blake 2021-05-06 09:01:44 -04:00 committed by GitHub
parent 72e2f310bd
commit b83e702d8a

74
it/main.py Normal file
View File

@ -0,0 +1,74 @@
# it, a shITtier version of ed
import importlib
import sys
oldinput = input
def input(*args, **kwargs):
message = args[0] if len(args) > 0 else ""
while 1:
try:
user_input = str(oldinput(message))
except KeyboardInterrupt:
pass
except EOFError:
sys.exit(0)
return user_input
def parsecommand(command):
casesensitive = True
escapes = ["\\"]
quotes = ["'", '"']
spaces = [" ", "\t"]
command = command.rstrip().lstrip()
inQuotes = 0
word = ""
parsed_command = []
for i in range(len(command)):
if (command[i] in quotes) and inQuotes == 0\
and (i == 0 \
or (i > 0 and command[i-1] != escape)):
inQuotes = command[i]
elif command[i] == inQuotes \
and (i > 0 and command[i-1] != escape):
inQuotes = 0
elif command[i] in space and inQuotes == 0\
and (i > 0 and command[i-1] != escape):
parsed_command += [word]
word = ""
elif command[i] != "\\" or (i == len(command) - 1) \
or not(command[i+1] in space + quotes):
word += command[i]
parsed_command += [word]
if parsed_command == ['']: return []
return parsed_command
class buffer: # all the information about the current file
content = []
dot = -1
filename = ""
saved = 0
def main(argc, argv):
file = buffer()
modules = {}
while True:
command = parsecommand(input())
if(command == []):
continue
try:
modules[command[0]] = importlib.import_module(command[0])
except ModuleNotFoundError as err:
print(err)
else:
file = modules[command[0]].main(len(command), command, file)
if __name__ == "__main__":
return main(len(sys.argv), sys.argv)