diff mbox

fixup! qapi: qapi.py: allow the "'" character be escaped

Message ID 87boj2o3eu.fsf_-_@blackfin.pond.sub.org
State New
Headers show

Commit Message

Markus Armbruster July 26, 2012, 5:09 p.m. UTC
Support escaping the escape character, and make more robust (don't die
for '', handle ' without matching '.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
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(-)

Comments

Peter Maydell July 26, 2012, 6:21 p.m. UTC | #1
On 26 July 2012 18:09, Markus Armbruster <armbru@redhat.com> wrote:
> Support escaping the escape character, and make more robust (don't die
> for '', handle ' without matching '.
>
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Yeah, let's do this the right way.

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>

-- PMM
Luiz Capitulino July 27, 2012, 2:29 p.m. UTC | #2
On Thu, 26 Jul 2012 19:09:13 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Support escaping the escape character, and make more robust (don't die
> for '', handle ' without matching '.
> 
> Signed-off-by: Markus Armbruster <armbru@redhat.com>

Can you please do you it on top of master so that I can apply it on the qmp
branch?

> ---
> 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):
Markus Armbruster July 28, 2012, 6:37 a.m. UTC | #3
Luiz Capitulino <lcapitulino@redhat.com> writes:

> On Thu, 26 Jul 2012 19:09:13 +0200
> Markus Armbruster <armbru@redhat.com> wrote:
>
>> Support escaping the escape character, and make more robust (don't die
>> for '', handle ' without matching '.
>> 
>> Signed-off-by: Markus Armbruster <armbru@redhat.com>
>
> Can you please do you it on top of master so that I can apply it on the qmp
> branch?

Have you tried squashing it into your commit?  Apply on top of your
series, then git-rebase -i --autosquash master.
Luiz Capitulino July 30, 2012, 1:09 p.m. UTC | #4
On Sat, 28 Jul 2012 08:37:03 +0200
Markus Armbruster <armbru@redhat.com> wrote:

> Luiz Capitulino <lcapitulino@redhat.com> writes:
> 
> > On Thu, 26 Jul 2012 19:09:13 +0200
> > Markus Armbruster <armbru@redhat.com> wrote:
> >
> >> Support escaping the escape character, and make more robust (don't die
> >> for '', handle ' without matching '.
> >> 
> >> Signed-off-by: Markus Armbruster <armbru@redhat.com>
> >
> > Can you please do you it on top of master so that I can apply it on the qmp
> > branch?
> 
> Have you tried squashing it into your commit?  

Oh, I didn't think about doing that. It works, now. Thanks.
diff mbox

Patch

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):