From 7e5607d534581756ccf86102314cd3a3de179ea9 Mon Sep 17 00:00:00 2001 From: Emmanuel Fleury Date: Fri, 26 May 2023 11:07:09 +0200 Subject: [PATCH] Take double-quote characters into account when parsing trigraph For now, the function parse_trigraph() defined in gobject/glib-mkenums script was not taking double-quotes characters into account: >>> parse_trigraph('name="eek, a comma"') {'name': '"eek', 'a': None} This patch take double-quotes characters into account: >>> parse_trigraph('name="eek, a comma"') {'name': 'eek, a comma'} Closes issue #65 --- gobject/glib-mkenums.in | 5 ++--- gobject/tests/mkenums.py | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/gobject/glib-mkenums.in b/gobject/glib-mkenums.in index e0c0b39af..353e53ae3 100755 --- a/gobject/glib-mkenums.in +++ b/gobject/glib-mkenums.in @@ -149,8 +149,7 @@ output = '' # Filename to write result into def parse_trigraph(opts): result = {} - - for opt in re.split(r'\s*,\s*', opts): + for opt in re.findall(r'(?:[^\s,"]|"(?:\\.|[^"])*")+', opts): opt = re.sub(r'^\s*', '', opt) opt = re.sub(r'\s*$', '', opt) m = re.search(r'(\w+)(?:=(.+))?', opt) @@ -161,7 +160,7 @@ def parse_trigraph(opts): val = groups[1] else: val = 1 - result[key] = val + result[key] = val.strip('"') if val is not None else None return result def parse_entries(file, file_name): diff --git a/gobject/tests/mkenums.py b/gobject/tests/mkenums.py index b58d23e79..0b40daeaf 100644 --- a/gobject/tests/mkenums.py +++ b/gobject/tests/mkenums.py @@ -520,6 +520,31 @@ comment: {standard_bottom_comment} "0", ) + def test_with_double_quotes(self): + """Test trigraphs with double-quoted expressions. Issue #65.""" + h_contents = """ + typedef enum { + FOO_VALUE /*< nick="eek, a comma" >*/ + } Foo; + """ + result = self.runMkenumsWithHeader(h_contents) + self.assertEqual("", result.err) + self.assertSingleEnum( + result, + "Foo", + "foo_", + "FOO_", + "", + "FOO", + "", + "enum", + "Enum", + "ENUM", + "FOO_VALUE", + "eek, a comma", + "0", + ) + def test_filename_basename_in_fhead_ftail(self): template_contents = """ /*** BEGIN file-header ***/