From nobody Sun Dec 14 08:06:22 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 1B792274B38; Mon, 28 Jul 2025 16:02:22 +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=1753718543; cv=none; b=F0esV9kE9Cx9yv0HQmZOnntIRyOWhsqRGfLBz3yq6vyWb2o18MitJfrUnRlFtUnrb44juAN7WyaIYqm+mfhX8G9zkdHdl+OXdy3yf60hVFrBvsj+VA/xN/dsnXbScFBgnFSDed+HmZZRfG5ip121w96ij/Tq5Osirjvj8v1AKNk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1753718543; c=relaxed/simple; bh=Re34NdFIFBEjM60ZOokQBSoSZa53NQDJZGofuj8tscY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jXWKxw7GzPE3+WQCow0teMXm4uFYweB81o4miEvo6yoU32KAAKl9cQ+0t65FmhTxfXEY0x+4QPHn8EfUWVBDStfZolJs/rtM3Kz8iORyJpjPsN8rYDIR6EaZ2p1NjeJBwbObfxwM6zpzMZGZKfy8PZaYYyivUMc3M12OaYQ3zlo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=G9WTJHLh; 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="G9WTJHLh" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 73773C113D0; Mon, 28 Jul 2025 16:02:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1753718542; bh=Re34NdFIFBEjM60ZOokQBSoSZa53NQDJZGofuj8tscY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=G9WTJHLhvpI0HtXYEFfFu5EMSp8YbHOPg/6SAELkZ/NBvbshoF0lnSEUXAJxlCiiw zWB3hl78PbGnmveFYqIYmfsJ/08ybTVyAwNjo0JoVw2SsFApYell+BNRf/cQn/+JF5 bu8R9BMJMeBzQbWwJfnkoWQONyMEBXX9KH8dhVDGoin1KAkYAXqbuFADweJyACwb8t Fp6JOyo56SDrWCQ55JgAcLZeDMbWdQE7ao4ygMqjHoFdiBdQ7fZvmE8dI4UiIR8szz pHBjAtNyzZIzsTvJu8/nM7N177MrOV7TrfaKAn1iqYI/18nyYm2mTE8K8hG/70atWr ISLUt9Yu7jkDg== Received: from mchehab by mail.kernel.org with local (Exim 4.98.2) (envelope-from ) id 1ugQIq-00000000GdK-2OZs; Mon, 28 Jul 2025 18:02:16 +0200 From: Mauro Carvalho Chehab To: "Message-ID :" , Linux Doc Mailing List Cc: Mauro Carvalho Chehab , "Akira Yokosawa" , "Breno Leitao" , "David S. Miller" , "Donald Hunter" , "Eric Dumazet" , "Ignacio Encinas Rubio" , "Jakub Kicinski" , "Jan Stancek" , "Jonathan Corbet" , "Marco Elver" , "Paolo Abeni" , "Randy Dunlap" , "Ruben Wauters" , "Shuah Khan" , "Simon Horman" , 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 v10 14/14] sphinx: parser_yaml.py: fix line numbers information Date: Mon, 28 Jul 2025 18:02:07 +0200 Message-ID: X-Mailer: git-send-email 2.49.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 --- 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.49.0