Skip to content

Instantly share code, notes, and snippets.

@lewis-carson
Last active February 26, 2018 16:35
Show Gist options
  • Save lewis-carson/2567f847c90fc40fdd6701073bb90519 to your computer and use it in GitHub Desktop.
Save lewis-carson/2567f847c90fc40fdd6701073bb90519 to your computer and use it in GitHub Desktop.
with open('out.py', 'w') as f:
f.write('')
def write(text, indent):
with open('out.py', 'a') as f:
f.write((indent * ' ') + text + '\n')
return
with open('in.txt') as f:
lines = f.readlines()
for linenonparse in lines:
if linenonparse[0] == ' ':
line = linenonparse[4:]
else:
line = linenonparse
indent = 0
if(line.startswith('::')):
write('def ' + line.replace('::', '').replace('\n', '') + '()' + ':', 0)
write('command = input(" >")\n done = False', 1)
indent = 1
name = line.replace('::', '')
if(line.startswith('/')):
parse = line.replace('/','').split(':')
if '=>' in parse[1]:
thing = parse[1].split("=>",1)[1].replace('\n', '') + '()'
write('if command == "'+parse[0]+'": print("'+parse[1].replace('\n', '')+'");'+thing+';done = True', 1)
else:
write('if command == "'+parse[0]+'": print("'+parse[1].replace('\n', '')+'"); done = True', 1)
if(line.startswith('?')):
write('if command == "look": print("'+line.replace('?', '').replace('\n', '')+'"); done = True', 1)
if(line.startswith('!')):
write('if done == False: print("'+line.replace('!', '').replace('\n', '')+'")', 1)
if(line.startswith('#')):
write(line.replace('#', '').replace('\n', '') + '()', 0)
if(line.startswith('-')):
write(name.replace('\n', '') + '()', 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment