mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
To: "Jonathan Corbet" <corbet@lwn.net>,
	Linux Doc Mailing List <linux-doc@vger.kernel.org>
Cc: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>,
	"Mauro Carvalho Chehab" <mchehab@kernel.org>,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org
Subject: [PATCH 05/23] tools: docs: parse_data_structs: make process_exceptions two stages
Date: Wed,  1 Oct 2025 16:49:28 +0200	[thread overview]
Message-ID: <da9ca5f2ce1ffcfb355e32e676ff013607c227e0.1759329363.git.mchehab+huawei@kernel.org> (raw)
In-Reply-To: <cover.1759329363.git.mchehab+huawei@kernel.org>

Split the logic which parses exceptions on two stages, preparing
the exceptions file to have rules that will affect xref generation.

For now, preserve the original API.

Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
---
 tools/docs/lib/parse_data_structs.py | 125 +++++++++++++++------------
 1 file changed, 71 insertions(+), 54 deletions(-)

diff --git a/tools/docs/lib/parse_data_structs.py b/tools/docs/lib/parse_data_structs.py
index 9ad621712103..46535a05ea4a 100755
--- a/tools/docs/lib/parse_data_structs.py
+++ b/tools/docs/lib/parse_data_structs.py
@@ -140,9 +140,41 @@ class ParseDataStructs:
 
         self.symbols = {}
 
+        self.ignore = []
+        self.replace = []
+
         for symbol_type in self.DEF_SYMBOL_TYPES:
             self.symbols[symbol_type] = {}
 
+    def read_exceptions(self, fname: str):
+        if not fname:
+            return
+
+        name = os.path.basename(fname)
+
+        with open(fname, "r", encoding="utf-8", errors="backslashreplace") as f:
+            for ln, line in enumerate(f):
+                ln += 1
+                line = line.strip()
+                if not line or line.startswith("#"):
+                    continue
+
+                # ignore rules
+                match = re.match(r"^ignore\s+(\w+)\s+(\S+)", line)
+
+                if match:
+                    self.ignore.append((ln, match.group(1), match.group(2)))
+                    continue
+
+                # replace rules
+                match = re.match(r"^replace\s+(\S+)\s+(\S+)\s+(\S+)", line)
+                if match:
+                    self.replace.append((ln, match.group(1), match.group(2),
+                                         match.group(3)))
+                    continue
+
+                sys.exit(f"{name}:{ln}: invalid line: {line}")
+
     def store_type(self, ln, symbol_type: str, symbol: str,
                    ref_name: str = None, replace_underscores: bool = True):
         """
@@ -277,75 +309,60 @@ class ParseDataStructs:
                         self.store_type(line_no, "struct", match.group(1))
                         break
 
-    def process_exceptions(self, fname: str):
+    def apply_exceptions(self):
         """
         Process exceptions file with rules to ignore or replace references.
         """
-        if not fname:
-            return
 
-        name = os.path.basename(fname)
+        # Handle ignore rules
+        for ln, c_type, symbol in self.ignore:
+            if c_type not in self.DEF_SYMBOL_TYPES:
+                sys.exit(f"{name}:{ln}: {c_type} is invalid")
 
-        with open(fname, "r", encoding="utf-8", errors="backslashreplace") as f:
-            for ln, line in enumerate(f):
-                ln += 1
-                line = line.strip()
-                if not line or line.startswith("#"):
-                    continue
+            d = self.symbols[c_type]
+            if symbol in d:
+                del d[symbol]
 
-                # Handle ignore rules
-                match = re.match(r"^ignore\s+(\w+)\s+(\S+)", line)
-                if match:
-                    c_type = match.group(1)
-                    symbol = match.group(2)
-
-                    if c_type not in self.DEF_SYMBOL_TYPES:
-                        sys.exit(f"{name}:{ln}: {c_type} is invalid")
-
-                    d = self.symbols[c_type]
-                    if symbol in d:
-                        del d[symbol]
-
-                    continue
-
-                # Handle replace rules
-                match = re.match(r"^replace\s+(\S+)\s+(\S+)\s+(\S+)", line)
-                if not match:
-                    sys.exit(f"{name}:{ln}: invalid line: {line}")
-
-                c_type, old, new = match.groups()
-
-                if c_type not in self.DEF_SYMBOL_TYPES:
-                    sys.exit(f"{name}:{ln}: {c_type} is invalid")
+        # Handle replace rules
+        for ln, c_type, old, new in self.replace:
+            if c_type not in self.DEF_SYMBOL_TYPES:
+                sys.exit(f"{name}:{ln}: {c_type} is invalid")
 
-                reftype = None
+            reftype = None
 
-                # Parse reference type when the type is specified
+            # Parse reference type when the type is specified
 
-                match = re.match(r"^\:c\:(data|func|macro|type)\:\`(.+)\`", new)
+            match = re.match(r"^\:c\:(data|func|macro|type)\:\`(.+)\`", new)
+            if match:
+                reftype = f":c:{match.group(1)}"
+                new = match.group(2)
+            else:
+                match = re.search(r"(\:ref)\:\`(.+)\`", new)
                 if match:
-                    reftype = f":c:{match.group(1)}"
+                    reftype = match.group(1)
                     new = match.group(2)
-                else:
-                    match = re.search(r"(\:ref)\:\`(.+)\`", new)
-                    if match:
-                        reftype = match.group(1)
-                        new = match.group(2)
 
-                # If the replacement rule doesn't have a type, get default
+            # If the replacement rule doesn't have a type, get default
+            if not reftype:
+                reftype = self.DEF_SYMBOL_TYPES[c_type].get("ref_type")
                 if not reftype:
-                    reftype = self.DEF_SYMBOL_TYPES[c_type].get("ref_type")
-                    if not reftype:
-                        reftype = self.DEF_SYMBOL_TYPES[c_type].get("real_type")
+                    reftype = self.DEF_SYMBOL_TYPES[c_type].get("real_type")
 
-                new_ref = f"{reftype}:`{old} <{new}>`"
+            new_ref = f"{reftype}:`{old} <{new}>`"
 
-                # Change self.symbols to use the replacement rule
-                if old in self.symbols[c_type]:
-                    (_, ln) = self.symbols[c_type][old]
-                    self.symbols[c_type][old] = (new_ref, ln)
-                else:
-                    print(f"{name}:{ln}: Warning: can't find {old} {c_type}")
+            # Change self.symbols to use the replacement rule
+            if old in self.symbols[c_type]:
+                (_, ln) = self.symbols[c_type][old]
+                self.symbols[c_type][old] = (new_ref, ln)
+            else:
+                print(f"{name}:{ln}: Warning: can't find {old} {c_type}")
+
+    def process_exceptions(self, fname: str):
+        """
+        Process exceptions file with rules to ignore or replace references.
+        """
+        self.read_exceptions(fname)
+        self.apply_exceptions()
 
     def debug_print(self):
         """
-- 
2.51.0


  parent reply	other threads:[~2025-10-01 14:49 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-01 14:49 [PATCH 00/23] Fix media uAPI cross references Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 01/23] tools: docs: parse_data_structs.py: drop contents header Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 02/23] tools: docs: parse_data_structs.py: output a line number Mauro Carvalho Chehab
2025-10-20 10:46   ` Hans Verkuil
2025-10-20 11:56     ` Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 03/23] docs: kernel_include.py: fix line numbers for TOC Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 04/23] docs: kernel_include.py: propose alternatives Mauro Carvalho Chehab
2025-10-01 14:49 ` Mauro Carvalho Chehab [this message]
2025-10-01 14:49 ` [PATCH 06/23] tools: docs: parse_data_structs.py: get rid of process_exceptions() Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 07/23] tools: docs: parse_data_structs.py: add namespace support Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 08/23] tools: docs: parse_data_structs.py: accept more reftypes Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 09/23] docs: media: dvb: use TOC instead of file contents at headers Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 10/23] docs: media: dvb: enable warnings for most headers Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 11/23] docs: media: rc: use TOC instead of file contents for LIRC header Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 12/23] docs: media: mediactl: use TOC instead of file contents Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 13/23] docs: kernel_include.py: use get_close_matches() to propose alternatives Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 14/23] docs: media: add missing c namespace to V4L headers Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 15/23] docs: media: videodev2.h.rst.exceptions: fix namespace on refs Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 16/23] media: docs: add a missing reference for VIDIOC_QUERY_CTRL Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 17/23] media: docs: videodev2.h.rst.exceptions: ignore struct __kernel_v4l2_timeval Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 18/23] media: docs: add some C domain missing references Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 19/23] docs: cec: cec.h.rst.exceptions: fix broken references from cec.h Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 20/23] docs: cec: show broken xrefs and show TOC instead of cec.h content Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 21/23] docs: media: dmx_types: place kerneldoc at the right namespace Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 22/23] docs: media: dvb: headers: warn about broken cross references Mauro Carvalho Chehab
2025-10-01 14:49 ` [PATCH 23/23] docs: media: dvb: fix dmx.h.rst.exceptions Mauro Carvalho Chehab
2025-10-17 20:08 ` [PATCH 00/23] Fix media uAPI cross references Jonathan Corbet
2025-10-18 10:53   ` Mauro Carvalho Chehab
2025-10-20 10:51 ` Hans Verkuil

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=da9ca5f2ce1ffcfb355e32e676ff013607c227e0.1759329363.git.mchehab+huawei@kernel.org \
    --to=mchehab+huawei@kernel.org \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®