Skip to content

Instantly share code, notes, and snippets.

@technillogue
Created January 19, 2012 11:59
Show Gist options
  • Save technillogue/1639614 to your computer and use it in GitHub Desktop.
Save technillogue/1639614 to your computer and use it in GitHub Desktop.
DuskWolf compiler
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