diff mbox series

[v3,07/49] qapi: mcgen() shouldn't indent # lines

Message ID 20180321115211.17937-8-marcandre.lureau@redhat.com
State New
Headers show
Series qapi: add #if pre-processor conditions to generated code | expand

Commit Message

Marc-André Lureau March 21, 2018, 11:51 a.m. UTC
Skip preprocessor lines when adding indentation, since that would
likely result in invalid code.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 scripts/qapi/common.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Markus Armbruster June 20, 2018, 3:14 p.m. UTC | #1
Marc-André Lureau <marcandre.lureau@redhat.com> writes:

> Skip preprocessor lines when adding indentation, since that would
> likely result in invalid code.
>
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  scripts/qapi/common.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
> index bc4ecd6c76..47efe79758 100644
> --- a/scripts/qapi/common.py
> +++ b/scripts/qapi/common.py
> @@ -1931,8 +1931,8 @@ def cgen(code, **kwds):
>      if indent_level:
>          indent = genindent(indent_level)
>          # re.subn() lacks flags support before Python 2.7, use re.compile()
> -        raw = re.subn(re.compile(r'^.', re.MULTILINE),
> -                      indent + r'\g<0>', raw)
> +        raw = re.subn(re.compile(r'^(?!(#|$))', re.MULTILINE),
> +                      indent, raw)
>          raw = raw[0]
>      return re.sub(re.escape(eatspace) + r' *', '', raw)

Reviewed-by: Markus Armbruster <armbru@redhat.com>
diff mbox series

Patch

diff --git a/scripts/qapi/common.py b/scripts/qapi/common.py
index bc4ecd6c76..47efe79758 100644
--- a/scripts/qapi/common.py
+++ b/scripts/qapi/common.py
@@ -1931,8 +1931,8 @@  def cgen(code, **kwds):
     if indent_level:
         indent = genindent(indent_level)
         # re.subn() lacks flags support before Python 2.7, use re.compile()
-        raw = re.subn(re.compile(r'^.', re.MULTILINE),
-                      indent + r'\g<0>', raw)
+        raw = re.subn(re.compile(r'^(?!(#|$))', re.MULTILINE),
+                      indent, raw)
         raw = raw[0]
     return re.sub(re.escape(eatspace) + r' *', '', raw)