<s> from grammar import Grammar <EOL> class ShellParser ( object ) : <EOL> services = None <EOL> def __init__ ( self ) : <EOL> self . tokens = None <EOL> def __call__ ( self , command_string ) : <EOL> self . parse ( command_string ) <EOL> def buildGrammar ( self ) : <EOL> self . grammar = Grammar ( ) <EOL> self . grammar . parser = self <EOL> self . grammar . makeBNF ( ) <EOL> return self . grammar <EOL> def parse ( self , cmd ) : <EOL> tokens = grammar . parseString ( cmd ) <EOL> out = """<STR_LIT>""" % ( tokens . commandtype , tokens . servicetype , tokens . action ) <EOL> self . tokens = tokens <EOL> return out <EOL> def _test ( ) : <EOL> import doctest , parser <EOL> doctest . testmod ( parser ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> _test ( ) </s>
