Commit e0d45df7 authored by Luiz Capitulino's avatar Luiz Capitulino
Browse files

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: default avatarMarkus Armbruster <armbru@redhat.com>
Reviewed-by: default avatarPeter Maydell <peter.maydell@linaro.org>
Signed-off-by: default avatarLuiz Capitulino <lcapitulino@redhat.com>
parent 02d2bd5d
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -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] == "'":
        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]
                data = data[1:]
            esc = False
            while True:
                if (data == ''):
                    raise Exception("Mismatched quotes")
                ch = data[0]
                data = data[1:]
                if esc:
                    string += ch
                    esc = False
                elif ch == "\\":
                    esc = True
                elif ch == "'":
                    break
                else:
                    string += ch
            yield string

def parse(tokens):