mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-07-29 13:23:54 -06:00
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: Markus Armbruster <armbru@redhat.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
02d2bd5d57
commit
e0d45df7a5
1 changed files with 21 additions and 10 deletions
|
@ -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:]
|
|
||||||
elif data[0] in ' \n':
|
|
||||||
data = data[1:]
|
|
||||||
elif data[0] == "'":
|
|
||||||
data = data[1:]
|
data = data[1:]
|
||||||
|
if ch in ['{', '}', ':', ',', '[', ']']:
|
||||||
|
yield ch
|
||||||
|
elif ch in ' \n':
|
||||||
|
None
|
||||||
|
elif ch == "'":
|
||||||
string = ''
|
string = ''
|
||||||
while data[0] != "'":
|
esc = False
|
||||||
string += data[0]
|
while True:
|
||||||
data = data[1:]
|
if (data == ''):
|
||||||
|
raise Exception("Mismatched quotes")
|
||||||
|
ch = data[0]
|
||||||
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):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue