From nobody Tue Oct 7 14:45:08 2025 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41A9518D; Fri, 11 Jul 2025 08:37:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752223049; cv=none; b=ATdC5B8f9fjSR4Z/oEzI4EqbJ+yPLIKXIxycKfp71vW/Hptc+W5bYQ9GvzHvzoddTU9uQBZxXMCPU5AAIakF1AIJEqh+OlyBRysbCgLgvoFVXqnZ6AiK70O/49EODP5XHH8NBodcprDQ81aoBE9f+nOJgXIBUkJ3BAY3gPQYjS8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752223049; c=relaxed/simple; bh=OHCIgiPuGTOLfp8ArVy61aLbLOSN/ySRGK+gWTBkLBU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CEivNZbl4eyYC8HoDhlmpsfkhplal+htTtXDOKWBcQPV02qbTYFEYfMWrxiRLygHvAhLaztfgN+K3GUgfJS64DP2kEYKHq3xUxMSd60Tm5+cD7VkmMboJ4AG/vXWtZvUaT8KiS3ZUh4aK0O1LStBV7lhS7FeZ9x9HlaUkjJWdek= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ThKvuZwq; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ThKvuZwq" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 118FDC4CEED; Fri, 11 Jul 2025 08:37:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1752223049; bh=OHCIgiPuGTOLfp8ArVy61aLbLOSN/ySRGK+gWTBkLBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ThKvuZwqdhuC5eWcMREi5ebn4Hmn8EDthtu/b4le/mSaNIBuNYYylhL6n4PDhDmwr pZFAawYh3d/ut4Qn1EMA3rLfjFwZilVks1Cy1aoRcPGg86XlABdrTbwOzA7tgqYaI5 KR3mnMI6irZwn3I6+9LKtn4rQfiMPqxmiBI7sWTEhg0uFl3HYenoT2vT+9d7n92RyX 6A1Gaeah2C+NOV3jPlZGcwB15BM89zYPBsGwby2yvWiDUkINI/u8OLWJqpB3JfXkOL WkDSFMf57nXRT/JkfsOMM25KTIEXZJBYj/+fH4hGGGcdrk9+sHU2Wn6QvYBA0r0Gl5 gfKjee6RjqbYg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1ua9G3-0000000FXSq-0eVb; Fri, 11 Jul 2025 10:37:27 +0200 From: Mauro Carvalho Chehab To: Linux Doc Mailing List , Jonathan Corbet Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Breno Leitao" , "David S. Miller" , "Donald Hunter" , "Eric Dumazet" , "Ignacio Encinas Rubio" , "Jan Stancek" , "Marco Elver" , "Mauro Carvalho Chehab" , "Paolo Abeni" , "Randy Dunlap" , "Ruben Wauters" , "Shuah Khan" , joel@joelfernandes.org, linux-kernel-mentees@lists.linux.dev, linux-kernel@vger.kernel.org, lkmm@lists.linux.dev, netdev@vger.kernel.org, peterz@infradead.org, stern@rowland.harvard.edu Subject: [PATCH v9 14/13] sphinx: parser_yaml.py: fix line numbers information Date: Fri, 11 Jul 2025 10:36:23 +0200 Message-ID: <4d1e0f5283ae1c6874cef272c5760035eb51278a.1752222934.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.50.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: Mauro Carvalho Chehab Content-Type: text/plain; charset="utf-8" As reported by Donald, this code: rst_parser =3D RSTParser() rst_parser.parse('\n'.join(result), document) breaks line parsing. As an alternative, I tested a variant of it: rst_parser.parse(result, document) but still line number was not preserved. As Donald noted, standard Parser classes don't have a direct mechanism to preserve line numbers from ViewList(). So, instead, let's use a mechanism similar to what we do already at kerneldoc.py: call the statemachine mechanism directly there. I double-checked when states and statemachine were introduced: both were back in 2002. I also tested doc build with docutils 0.16 and 0.21.2. It worked with both, so it seems to be stable enough for our needs. Reported-by: Donald Hunter Closes: https://lore.kernel.org/linux-doc/m24ivk78ng.fsf@gmail.com/T/#u Signed-off-by: Mauro Carvalho Chehab --- PS.: I'm opting to send this as 14/13 to avoid respanning the entire series again just due to this extra change. Documentation/sphinx/parser_yaml.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Documentation/sphinx/parser_yaml.py b/Documentation/sphinx/par= ser_yaml.py index 1602b31f448e..634d84a202fc 100755 --- a/Documentation/sphinx/parser_yaml.py +++ b/Documentation/sphinx/parser_yaml.py @@ -11,7 +11,9 @@ import sys =20 from pprint import pformat =20 +from docutils import statemachine from docutils.parsers.rst import Parser as RSTParser +from docutils.parsers.rst import states from docutils.statemachine import ViewList =20 from sphinx.util import logging @@ -56,6 +58,8 @@ class YamlParser(Parser): =20 re_lineno =3D re.compile(r"\.\. LINENO ([0-9]+)$") =20 + tab_width =3D 8 + def rst_parse(self, inputstring, document, msg): """ Receives a ReST content that was previously converted by the @@ -66,10 +70,18 @@ class YamlParser(Parser): =20 result =3D ViewList() =20 + self.statemachine =3D states.RSTStateMachine(state_classes=3Dstate= s.state_classes, + initial_state=3D'Body', + debug=3Ddocument.report= er.debug_flag) + try: # Parse message with RSTParser lineoffset =3D 0; - for line in msg.split('\n'): + + lines =3D statemachine.string2lines(msg, self.tab_width, + convert_whitespace=3DTrue) + + for line in lines: match =3D self.re_lineno.match(line) if match: lineoffset =3D int(match.group(1)) @@ -77,12 +89,7 @@ class YamlParser(Parser): =20 result.append(line, document.current_source, lineoffset) =20 - # Fix backward compatibility with docutils < 0.17.1 - if "tab_width" not in vars(document.settings): - document.settings.tab_width =3D 8 - - rst_parser =3D RSTParser() - rst_parser.parse('\n'.join(result), document) + self.statemachine.run(result, document) =20 except Exception as e: document.reporter.error("YAML parsing error: %s" % pformat(e)) --=20 2.50.0