diff --git a/main.py b/main.py index a5ae534..703bfe1 100755 --- a/main.py +++ b/main.py @@ -54,8 +54,8 @@ return None def run_set(env, ast): - env[ast[1]] = run_statement(env, ast[2]) - return env[ast[1]] + env[ast.subject] = run_statement(env, ast.statement) + return env[ast.subject] def run_if(env, ast): print("Unimplemented if") @@ -64,13 +64,12 @@ def run_command(env, ast): if ast.__class__ == parse.Statement: return run_statement(env, ast) + elif ast.__class__ == parse.Set: + return run_set(env, ast) elif ast.__class__ == parse.Conditional: return run_if(env, ast) - type = ast[0] - if type == "set": - return run_set(env, ast) else: - print("Unknown command type %s" % (ast)) + print("Unknown command %s" % (ast)) return None def main(args): diff --git a/parse.py b/parse.py index 1014be8..0cb0f25 100644 --- a/parse.py +++ b/parse.py @@ -88,6 +88,14 @@ def __repr__(self): return "Statement(subject %s, verb '%s', arguments %s)" % (self.subject, self.verb, self.arguments) +class Set: + def __init__(self, subject, statement): + self.subject = subject + self.statement = statement + + def __repr__(self): + return "Set(subject %s, statement %s)" % (self.subject, self.statement) + class Conditional: def __init__(self, test, success, failure): self.test = test @@ -193,8 +201,9 @@ if not ast: log.log(log.PARSER, log.NORMAL, "While parsing statement") return None - log.log(log.PARSER, log.DEBUG, "Parsed set for %s" % (subject)) - return ('set', subject, ast) + set = Set(subject, ast) + log.log(log.PARSER, log.DEBUG, "Parsed %s" % (set)) + return set def parse_if(self): log.log(log.PARSER, log.TRACE, "Parsing if test condition...")