aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorLuiz Capitulino <lcapitulino@redhat.com>2012-06-29 20:53:37 -0300
committerLuiz Capitulino <lcapitulino@redhat.com>2012-08-01 18:09:29 -0300
commite0d45df7a5794b6821d2f8893a7f343109debab9 (patch)
treeabdcb756748095b76b32fa0051a08630af53755f /scripts
parent02d2bd5d57812154cfb978bc2098cf49d551583d (diff)
downloadqemu-e0d45df7a5794b6821d2f8893a7f343109debab9.zip
qemu-e0d45df7a5794b6821d2f8893a7f343109debab9.tar.gz
qemu-e0d45df7a5794b6821d2f8893a7f343109debab9.tar.bz2
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>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/qapi.py31
1 files changed, 21 insertions, 10 deletions
diff --git a/scripts/qapi.py b/scripts/qapi.py
index 8082af3..d3b8b4d 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -13,18 +13,29 @@ from ordereddict import OrderedDict
def tokenize(data):
while len(data):
- if data[0] in ['{', '}', ':', ',', '[', ']']:
- yield data[0]
- data = data[1:]
- elif data[0] in ' \n':
- data = data[1:]
- elif data[0] == "'":
- data = data[1:]
+ ch = data[0]
+ data = data[1:]
+ if ch in ['{', '}', ':', ',', '[', ']']:
+ yield ch
+ elif ch in ' \n':
+ None
+ elif ch == "'":
string = ''
- while data[0] != "'":
- string += data[0]
+ esc = False
+ while True:
+ 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
def parse(tokens):