Example #1
0
class Parser():
    def __init__(self):
        self.tokenizer = Tokenizer()

    def parse(self, inputString):
        tokens = self.tokenizer.tokenize(inputString)

        command = Command()
        if tokens[0].value == EXIT:
            exit()
        elif tokens[0].value == ADD_PENDING_CONTRACT:
            parserdObject = self.parseContract(tokens)
            command = AddContract(parserdObject)
        elif tokens[0].value == ADD_PERSON:
            parserdObject = self.parsePerson(tokens)
            command = AddPerson(parserdObject)
        elif tokens[0].value == ADD_TEAM:
            parserdObject = self.parseTeam(tokens)
            command = AddTeam(parserdObject)
        else:
            raise KeyError('unknown command')

        return command

    def parseContract(self, tokens):
        contract = Contract()
        contract.contractType = tokens[1].value
        contract.person = tokens[2].value
        contract.team = tokens[3].value
        return contract

    def parsePerson(self, tokens):
        person = Person()
        person.personName = tokens[1].value

        if tokens[2].value == 'player':
            person.role = Player()
        elif tokens[2].value == 'staff':
            person.role = Staff()
        else:
            raise KeyError('unknown role')

        return person

    def parseTeam(self, tokens):
        team = Team()
        team.teamName = tokens[1].value
        return team
Example #2
0
class Parser():
	def __init__(self):
		self.tokenizer = Tokenizer()

	def parse(self, inputString):
		tokens = self.tokenizer.tokenize(inputString)
		
		command = Command()
		if tokens[0].value == EXIT:
			exit()
		elif tokens[0].value == ADD_PENDING_CONTRACT:
			parserdObject = self.parseContract(tokens)
			command = AddContract(parserdObject)
		elif tokens[0].value == ADD_PERSON:
			parserdObject = self.parsePerson(tokens)
			command = AddPerson(parserdObject)
		elif tokens[0].value == ADD_TEAM:
			parserdObject = self.parseTeam(tokens)
			command = AddTeam(parserdObject)
		else:
			raise KeyError('unknown command')
		
		return command

	def parseContract(self, tokens):
		contract = Contract()
		contract.contractType = tokens[1].value
		contract.person = tokens[2].value
		contract.team = tokens[3].value
		return contract

	def parsePerson(self, tokens):
		person = Person()
		person.personName = tokens[1].value

		if tokens[2].value == 'player':
			person.role = Player()
		elif tokens[2].value == 'staff':
			person.role = Staff()
		else:
			raise KeyError('unknown role')

		return person

	def parseTeam(self, tokens):
		team = Team()
		team.teamName = tokens[1].value
		return team
Example #3
0
 def __init__(self):
     self.tokenizer = Tokenizer()
Example #4
0
	def __init__(self):
		self.tokenizer = Tokenizer()