diff --git a/src/interpreter.py b/src/interpreter.py new file mode 100644 index 0000000..86cd37e --- /dev/null +++ b/src/interpreter.py @@ -0,0 +1,78 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from world import World + + +# +# FIXME: conceptually a bit messed up, especially needs work on how the argument +# gets passed to the OptionCommand +# + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string, arg): + self.name = name + self.doc_string = doc_string + self.arg = arg + + def act(self): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + +class DefineCommand(object): + ''' + This is the super class for all define commands. It should be extended + for each individual command, like define-place, define-monster, etc. + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) + + def execute(self): + ''' + Execute this command with all its options + ''' + for o in self.option_registry: + o.act(arg) + + +define_command_registry = [] + +def register_define_command(def_com): + define_command_registry.append(def_com) + + +class Parser(object): + ''' + The actual parser class. It reads in a world file and transforms it into + a series of DefineCommands. + ''' + + def __init__(self, world_file): + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/src/interpreter.py b/src/interpreter.py new file mode 100644 index 0000000..86cd37e --- /dev/null +++ b/src/interpreter.py @@ -0,0 +1,78 @@ +#!/usr/bin/python3 +# +# Atlantis is a framework for creating multi-user dungeon worlds. +# This module reads in a world file and parses it. This is where the +# structure of the Atlantis language is defined. +# +# Licensed under the terms of the GPLv3 +# author: Daniel Vedder +# date: 02/05/2015 +# + +from world import World + + +# +# FIXME: conceptually a bit messed up, especially needs work on how the argument +# gets passed to the OptionCommand +# + + +class OptionCommand(object): + ''' + This is the super class for all option commands. (A define command + includes one or more option commands.) + ''' + + def __init__(self, name, doc_string, arg): + self.name = name + self.doc_string = doc_string + self.arg = arg + + def act(self): + ''' + Carry out this option commands action with argument arg. + Has to be extended by subclasses! + ''' + raise NotImplementedError + + +class DefineCommand(object): + ''' + This is the super class for all define commands. It should be extended + for each individual command, like define-place, define-monster, etc. + ''' + + def __init__(self, name, doc_string): + self.name = name + self.doc_string = doc_string + self.option_registry = [] + + def add_option(self, option_command): + self.option_registry.append(option_command) + + def execute(self): + ''' + Execute this command with all its options + ''' + for o in self.option_registry: + o.act(arg) + + +define_command_registry = [] + +def register_define_command(def_com): + define_command_registry.append(def_com) + + +class Parser(object): + ''' + The actual parser class. It reads in a world file and transforms it into + a series of DefineCommands. + ''' + + def __init__(self, world_file): + self.world_file = world_file + + def generate_world(self): + return World() diff --git a/src/parser.py b/src/parser.py deleted file mode 100644 index 86cd37e..0000000 --- a/src/parser.py +++ /dev/null @@ -1,78 +0,0 @@ -#!/usr/bin/python3 -# -# Atlantis is a framework for creating multi-user dungeon worlds. -# This module reads in a world file and parses it. This is where the -# structure of the Atlantis language is defined. -# -# Licensed under the terms of the GPLv3 -# author: Daniel Vedder -# date: 02/05/2015 -# - -from world import World - - -# -# FIXME: conceptually a bit messed up, especially needs work on how the argument -# gets passed to the OptionCommand -# - - -class OptionCommand(object): - ''' - This is the super class for all option commands. (A define command - includes one or more option commands.) - ''' - - def __init__(self, name, doc_string, arg): - self.name = name - self.doc_string = doc_string - self.arg = arg - - def act(self): - ''' - Carry out this option commands action with argument arg. - Has to be extended by subclasses! - ''' - raise NotImplementedError - - -class DefineCommand(object): - ''' - This is the super class for all define commands. It should be extended - for each individual command, like define-place, define-monster, etc. - ''' - - def __init__(self, name, doc_string): - self.name = name - self.doc_string = doc_string - self.option_registry = [] - - def add_option(self, option_command): - self.option_registry.append(option_command) - - def execute(self): - ''' - Execute this command with all its options - ''' - for o in self.option_registry: - o.act(arg) - - -define_command_registry = [] - -def register_define_command(def_com): - define_command_registry.append(def_com) - - -class Parser(object): - ''' - The actual parser class. It reads in a world file and transforms it into - a series of DefineCommands. - ''' - - def __init__(self, world_file): - self.world_file = world_file - - def generate_world(self): - return World()