提交 e0d45df7 编写于 作者: L Luiz Capitulino

qapi: qapi.py: allow the "'" character to be escaped

Support escaping the escape character, and make more robust (don't die
for '', handle ' without matching '.
Signed-off-by: NMarkus Armbruster <armbru@redhat.com>
Reviewed-by: NPeter Maydell <peter.maydell@linaro.org>
Signed-off-by: NLuiz Capitulino <lcapitulino@redhat.com>
上级 02d2bd5d
...@@ -13,18 +13,29 @@ from ordereddict import OrderedDict ...@@ -13,18 +13,29 @@ from ordereddict import OrderedDict
def tokenize(data): def tokenize(data):
while len(data): while len(data):
if data[0] in ['{', '}', ':', ',', '[', ']']: ch = data[0]
yield data[0] data = data[1:]
data = data[1:] if ch in ['{', '}', ':', ',', '[', ']']:
elif data[0] in ' \n': yield ch
data = data[1:] elif ch in ' \n':
elif data[0] == "'": None
data = data[1:] elif ch == "'":
string = '' string = ''
while data[0] != "'": esc = False
string += data[0] while True:
if (data == ''):
raise Exception("Mismatched quotes")
ch = data[0]
data = data[1:] data = data[1:]
data = data[1:] if esc:
string += ch
esc = False
elif ch == "\\":
esc = True
elif ch == "'":
break
else:
string += ch
yield string yield string
def parse(tokens): def parse(tokens):
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册