Created
January 19, 2012 11:59
-
-
Save technillogue/1639614 to your computer and use it in GitHub Desktop.
DuskWolf compiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
improt string, sysy | |
containers = ["on"] | |
cmd_trans = {"on": "while"} | |
lineargs = {"on": ["event"], "comment": ["text"], "var": ["name", "value"]} | |
NAME = "foo" | |
source = open(name + ".dw").read() | |
compiled = open(name + ".json", "w") | |
compiled.write("[\n") | |
for line in source: | |
newline = "\t" | |
for char in line: | |
if char in string.whitespace: | |
newline += char | |
else: | |
break | |
keyword, *args = line.split() | |
if keyword is "end": | |
newline = newline[:-1] + "]}' | |
else: | |
newline += '{"a": "%s", ' % cmd_trans[keyword] if keyword in cmd_trans else keyword | |
#add keyword | |
for i, arg in enumerate(args): | |
newline += "\"" + lineargs[keyword][i] + '": ' + arg + ", " | |
#add args | |
if keyword in containers: | |
newline += "actions: [" | |
else: | |
newline += "}" | |
compiled.write(line + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment