qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH] fixup! qapi: qapi.py: allow the "'" character be es


From: Markus Armbruster
Subject: [Qemu-devel] [PATCH] fixup! qapi: qapi.py: allow the "'" character be escaped
Date: Thu, 26 Jul 2012 19:09:13 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.97 (gnu/linux)

Support escaping the escape character, and make more robust (don't die
for '', handle ' without matching '.

Signed-off-by: Markus Armbruster <address@hidden>
---
Luiz made me do this.  Fixes up his 07/11.

Generates identical qmp-commands.h qapi-types.h qapi-visit.h
qapi-errors.h tests/test-qapi-types.h tests/test-qapi-visit.h
tests/test-qmp-commands.h qapi-generated/qga-qapi-types.h
qapi-generated/qga-qapi-visit.h qapi-generated/qga-qmp-commands.h

 scripts/qapi.py |   31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)


diff --git a/scripts/qapi.py b/scripts/qapi.py
index 9aa518f..169ea78 100644
--- a/scripts/qapi.py
+++ b/scripts/qapi.py
@@ -13,20 +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 = ''
+            esc = False
             while True:
-                if data[0] == "'" and string[len(string)-1] != "\\":
-                    break
-                string += data[0]
+                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):
-- 
1.7.10.4




reply via email to

[Prev in Thread] Current Thread [Next in Thread]