Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def value_assign(self, end_token=None):
"""
We are expecting a value (literal, list, dict, tuple).
If end_token then we are inside a list, dict or tuple so we are allow
newlines and also check for the end token.
"""
while True:
token = self.next()
t_value = token["value"]
if end_token:
if t_value == end_token:
raise self.ParseEnd()
elif t_value == "\n":
continue
if token["type"] == "literal":
return self.make_value(t_value)
if token["type"] == "function":
return self.config_function(token)
elif t_value == "[":
return self.make_list()
elif t_value == "{":
return self.make_dict()
elif t_value == "(":
return tuple(self.make_list(end_token=")"))
else:
self.error("Value expected", previous=not (end_token))
def dict_key(self):
"""
Find the next key in a dict. We skip any newlines and check for if the
dict has ended.
"""
while True:
token = self.next()
t_value = token["value"]
if t_value == "\n":
continue
if t_value == "}":
raise self.ParseEnd()
if token["type"] == "literal":
return self.make_value(t_value)
self.error("Invalid Key")
def separator(self, separator=",", end_token=None):
"""
Read through tokens till the required separator is found. We ignore
newlines. If an end token is supplied raise a ParseEnd exception if it
is found.
"""
while True:
token = self.next()
t_value = token["value"]
if end_token and t_value == end_token:
raise self.ParseEnd()
if t_value == separator:
return
if t_value == "\n":
continue
self.error("Unexpected character")