Re: [PATCH v5 10/15] docs: sphinx: add a parser for yaml files for Netlink specs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Em Tue, 17 Jun 2025 15:40:49 +0200
Mauro Carvalho Chehab <mchehab+huawei@xxxxxxxxxx> escreveu:

> > > +            # Parse message with RSTParser
> > > +            for i, line in enumerate(msg.split('\n')):
> > > +                result.append(line, document.current_source, i)    
> > 
> > This has the effect of associating line numbers from the generated ReST
> > with the source .yaml file, right? So errors will be reported against
> > the wrong place in the file. Is there any way to show the cause of the
> > error in the intermediate ReST?  
> 
> Yes, but this will require modifying the parser. I prefer merging this
> series without such change, and then having a separate changeset
> addressing it.
> 
> There are two ways we can do that:
> 
> 1. The parser can add a ReST comment with the line number. This
>    is what it is done by kerneldoc.py Sphinx extension:
> 
> 	lineoffset = 0
> 	line_regex = re.compile(r"^\.\. LINENO ([0-9]+)$")
>         for line in lines:
>             match = line_regex.search(line)
>             if match:
>                 lineoffset = int(match.group(1)) - 1 # sphinx counts lines from 0
>             else:
>                 doc = str(env.srcdir) + "/" + env.docname + ":" + str(self.lineno)
>                 result.append(line, doc + ": " + filename, lineoffset)
>                 lineoffset += 1
> 
>    I kept the same way after its conversion to Python, as right now,
>    it supports both a Python class and a command lin command. I may
>    eventually clean it up in the future.
> 
> 2. making the parser return a tuple. At kernel_abi.py, as the parser
>    returns content from multiple files, such tuple is:
> 
> 		 (rst_output, filename, line_number)
> 
>    and the code for it is (cleaned up):
> 
> 	for msg, f, ln in kernel_abi.doc(show_file=show_file,
>                                          show_symbols=show_symbols,
>                                          filter_path=abi_type):
> 
>             lines = statemachine.string2lines(msg, tab_width,
>                                               convert_whitespace=True)
> 
>             for line in lines:
>                 content.append(line, f, ln - 1) # sphinx counts lines from 0
> 
> (2) is cleaner and faster, but (1) is easier to implement on an 
> already-existing code.

The logic below implements (1). This seems to be the easiest way for
pyyaml. I will submit as 2 separate patches at the end of the next
version.

Please notice that I didn't check yet for the "quality" of the
line numbers. Some tweaks could be needed later on.

Regards,
Mauro

---


[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux FS]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Device Mapper]     [Linux Resources]

  Powered by Linux