[PATCH v2 15/25] docs: kdoc_re: properly handle strings and escape chars on it

Mauro Carvalho Chehab posted 25 patches 1 week, 3 days ago
There is a newer version of this series
[PATCH v2 15/25] docs: kdoc_re: properly handle strings and escape chars on it
Posted by Mauro Carvalho Chehab 1 week, 3 days ago
The logic inside NestedMatch currently doesn't consider that
function arguments may have chars and strings, which may
eventually contain delimiters.

Add logic to handle strings and escape characters on them.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/lib/python/kdoc/kdoc_re.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/tools/lib/python/kdoc/kdoc_re.py b/tools/lib/python/kdoc/kdoc_re.py
index a0402c065d3a..1861799f1966 100644
--- a/tools/lib/python/kdoc/kdoc_re.py
+++ b/tools/lib/python/kdoc/kdoc_re.py
@@ -195,6 +195,8 @@ class NestedMatch:
         for match_re in regex.finditer(line):
             start = match_re.start()
             offset = match_re.end()
+            string_char = None
+            escape = False
 
             d = line[offset - 1]
             if d not in self.DELIMITER_PAIRS:
@@ -208,6 +210,22 @@ class NestedMatch:
 
                 d = line[pos]
 
+                if escape:
+                    escape = False
+                    continue
+
+                if string_char:
+                    if d == '\\':
+                        escape = True
+                    elif d == string_char:
+                        string_char = None
+
+                    continue
+
+                if d in ('"', "'"):
+                    string_char = d
+                    continue
+
                 if d in self.DELIMITER_PAIRS:
                     end = self.DELIMITER_PAIRS[d]
 
-- 
2.52.0
RE: [Intel-wired-lan] [PATCH v2 15/25] docs: kdoc_re: properly handle strings and escape chars on it
Posted by Loktionov, Aleksandr 1 week, 3 days ago

> -----Original Message-----
> From: Intel-wired-lan <intel-wired-lan-bounces@osuosl.org> On Behalf
> Of Mauro Carvalho Chehab
> Sent: Wednesday, January 28, 2026 5:50 PM
> To: Jonathan Corbet <corbet@lwn.net>; Linux Doc Mailing List <linux-
> doc@vger.kernel.org>
> Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>;
> bpf@vger.kernel.org; intel-wired-lan@lists.osuosl.org; linux-
> kernel@vger.kernel.org; netdev@vger.kernel.org; Peter Zijlstra
> <peterz@infradead.org>; Randy Dunlap <rdunlap@infradead.org>; Stephen
> Rothwell <sfr@canb.auug.org.au>
> Subject: [Intel-wired-lan] [PATCH v2 15/25] docs: kdoc_re: properly
> handle strings and escape chars on it
> 
> The logic inside NestedMatch currently doesn't consider that function
> arguments may have chars and strings, which may eventually contain
> delimiters.
> 
> Add logic to handle strings and escape characters on them.
> 
> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
> ---
>  tools/lib/python/kdoc/kdoc_re.py | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
> 
> diff --git a/tools/lib/python/kdoc/kdoc_re.py
> b/tools/lib/python/kdoc/kdoc_re.py
> index a0402c065d3a..1861799f1966 100644
> --- a/tools/lib/python/kdoc/kdoc_re.py
> +++ b/tools/lib/python/kdoc/kdoc_re.py
> @@ -195,6 +195,8 @@ class NestedMatch:
>          for match_re in regex.finditer(line):
>              start = match_re.start()
>              offset = match_re.end()
> +            string_char = None
> +            escape = False
> 
>              d = line[offset - 1]
>              if d not in self.DELIMITER_PAIRS:
> @@ -208,6 +210,22 @@ class NestedMatch:
> 
>                  d = line[pos]
> 
> +                if escape:
> +                    escape = False
> +                    continue
> +
> +                if string_char:
> +                    if d == '\\':
> +                        escape = True
> +                    elif d == string_char:
> +                        string_char = None
> +
> +                    continue
> +
> +                if d in ('"', "'"):
> +                    string_char = d
> +                    continue
> +
>                  if d in self.DELIMITER_PAIRS:
>                      end = self.DELIMITER_PAIRS[d]
> 
> --
> 2.52.0
Reviewed-by: Aleksandr Loktionov <aleksandr.loktionov@intel.com>