Esempio n. 1
0
	def parse(cls, token_list, parent, allowed, ctx):
		'''
		Parse section from token list
		@param token_list: a token list to be used
		@type token_list: L{SpecTokenList}
		@param parent: parent section or None
		@type parent: L{SpecSection}
		@param allowed: allowed sections within the section
		@type allowed: list of L{SpecSection}
		@param ctx: parsing context
		@type ctx: L{SpecModelParser}
		@return: parsed section
		@rtype: L{SpecSection}
		'''
		ret = SpecExpressionParser.obj(parent)

		tokens = SpecTokenList()
		# let's assume, that the very first token is a part of an expression
		tokens.token_list_append(token_list.get())

		while True:
			tkn = token_list.touch()
			if str(tkn) == '>=' or str(tkn) == '<=' \
					or str(tkn) == '<' or str(tkn) == '>' \
					or str(tkn) == '!=' or str(tkn) == '==' \
					or str(tkn) == '&&' or str(tkn) == '||':
				tokens.token_list_append(token_list.get())
				if token_list.touch().is_eof():
					raise SpecBadToken("Unexpected EOF, expected expression termination")
				tokens.token_list_append(token_list.get())
				continue
			else:
				break

		ret.set_tokens(tokens)
		return ret
Esempio n. 2
0
	def parse_entry(cls, token_list, parent, ctx):
		'''
		Parse a changelog entry
		@param token_list: a token list to be used
		@type token_list: L{SpecTokenList}
		@param parent: parent section or None
		@type parent: L{SpecSection}
		@param ctx: parsing context
		@type ctx: L{SpecModelParser}
		@return: parsed section
		@rtype: L{SpecSection}

		'''
		def parse_date(date):
			s = str(date[0]) + ' ' + str(date[1]) + ' ' + str(date[2]) + ' ' + str(date[3])
			return datetime.datetime.strptime(s, '%a %b %d %Y')

		def changelog_entry_beginning_callback(obj, token_list):
			# is there some section?
			if obj.section_beginning_callback(obj, token_list):
				# changelog message can consist of keyword like:
				# - Add missing Requires: golang(github.com/gorilla/mux) to devel
				tkn = token_list.touch()
				if not tkn.same_line(token_list[token_list.get_pointer() - 1]):
					return True

			# or is there another changelog entry?
			return str(token_list.touch()) == '*'

		entry = SpecChangelogParser.obj.SpecStChangelogEntry(parent)

		star = token_list.get()
		if str(star) != '*':
			token_list.unget()
			raise SpecBadToken("Expected token '*', got '%s'" % star)
		entry.set_star(star)

		date = SpecTokenList()
		for _ in xrange(0, 4):
			date.token_list_append(token_list.get())
		entry.set_date(date)

		date_parsed = parse_date(date)
		entry.set_date_parsed(date_parsed)

		user = SpecTokenList()
		while not str(token_list.touch()).startswith('<'):
			user.token_list_append(token_list.get())
		entry.set_user(user)

		user_email = token_list.get()
		entry.set_user_email(user_email)

		# version delim is optional here, if not stated, let's skip it
		if str(token_list.touch()) == '-':
			entry.set_version_delim(token_list.get())

		version = token_list.get()
		entry.set_version(version)

		entry.set_message(token_list.get_while_not(
									functools.partial(changelog_entry_beginning_callback, ctx)
									)
								)

		return entry