[PATCH 39/57] qapi/source: allow multi-line QAPISourceInfo advancing

John Snow posted 57 patches 4 weeks ago
There is a newer version of this series
[PATCH 39/57] qapi/source: allow multi-line QAPISourceInfo advancing
Posted by John Snow 4 weeks ago
This is for the sake of the new rST generator (the "transmogrifier") so
we can advance multiple lines on occasion while keeping the
generated<-->source mappings accurate.

next_line now simply takes an optional n parameter which chooses the
number of lines to advance.

RFC: Here's the exorbitant detail on why I want this:

This is used mainly when converting section syntax in free-form
documentation to more traditional rST section header syntax, which
does not always line up 1:1 for line counts.

For example:

```
 ##
 # = Section     <-- Info is pointing here, "L1"
 #
 # Lorem Ipsum
 ##
```

would be transformed to rST as:

```
=======        <-- L1
Section        <-- L1
=======        <-- L1
               <-- L2
Lorem Ipsum    <-- L3
```

After consuming the single "Section" line from the source, we want to
advance the source pointer to the next non-empty line which requires
jumping by more than one line.

Signed-off-by: John Snow <jsnow@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
---
 scripts/qapi/source.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py
index 7b379fdc925..ffdc3f482ac 100644
--- a/scripts/qapi/source.py
+++ b/scripts/qapi/source.py
@@ -47,9 +47,9 @@ def set_defn(self, meta: str, name: str) -> None:
         self.defn_meta = meta
         self.defn_name = name
 
-    def next_line(self: T) -> T:
+    def next_line(self: T, n: int = 1) -> T:
         info = copy.copy(self)
-        info.line += 1
+        info.line += n
         return info
 
     def loc(self) -> str:
-- 
2.48.1
Re: [PATCH 39/57] qapi/source: allow multi-line QAPISourceInfo advancing
Posted by Markus Armbruster 4 weeks ago
John Snow <jsnow@redhat.com> writes:

> This is for the sake of the new rST generator (the "transmogrifier") so
> we can advance multiple lines on occasion while keeping the
> generated<-->source mappings accurate.
>
> next_line now simply takes an optional n parameter which chooses the
> number of lines to advance.
>
> RFC: Here's the exorbitant detail on why I want this:
>
> This is used mainly when converting section syntax in free-form
> documentation to more traditional rST section header syntax, which
> does not always line up 1:1 for line counts.

Obvious way to resolve the RFC:

  The next patch will use this when converting ...

>
> For example:
>
> ```
>  ##
>  # = Section     <-- Info is pointing here, "L1"
>  #
>  # Lorem Ipsum
>  ##
> ```
>
> would be transformed to rST as:
>
> ```
> =======        <-- L1
> Section        <-- L1
> =======        <-- L1
>                <-- L2
> Lorem Ipsum    <-- L3
> ```

Not a demand, just wondering: could we drop our headings syntax and just
use rST?

>
> After consuming the single "Section" line from the source, we want to
> advance the source pointer to the next non-empty line which requires
> jumping by more than one line.
>
> Signed-off-by: John Snow <jsnow@redhat.com>
> Reviewed-by: Markus Armbruster <armbru@redhat.com>
> ---
>  scripts/qapi/source.py | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/scripts/qapi/source.py b/scripts/qapi/source.py
> index 7b379fdc925..ffdc3f482ac 100644
> --- a/scripts/qapi/source.py
> +++ b/scripts/qapi/source.py
> @@ -47,9 +47,9 @@ def set_defn(self, meta: str, name: str) -> None:
>          self.defn_meta = meta
>          self.defn_name = name
>  
> -    def next_line(self: T) -> T:
> +    def next_line(self: T, n: int = 1) -> T:
>          info = copy.copy(self)
> -        info.line += 1
> +        info.line += n
>          return info
>  
>      def loc(self) -> str:
Re: [PATCH 39/57] qapi/source: allow multi-line QAPISourceInfo advancing
Posted by John Snow 3 weeks, 6 days ago
On Wed, Mar 5, 2025 at 5:35 AM Markus Armbruster <armbru@redhat.com> wrote:

> John Snow <jsnow@redhat.com> writes:
>
> > This is for the sake of the new rST generator (the "transmogrifier") so
> > we can advance multiple lines on occasion while keeping the
> > generated<-->source mappings accurate.
> >
> > next_line now simply takes an optional n parameter which chooses the
> > number of lines to advance.
> >
> > RFC: Here's the exorbitant detail on why I want this:
> >
> > This is used mainly when converting section syntax in free-form
> > documentation to more traditional rST section header syntax, which
> > does not always line up 1:1 for line counts.
>
> Obvious way to resolve the RFC:
>
>   The next patch will use this when converting ...
>
> >
> > For example:
> >
> > ```
> >  ##
> >  # = Section     <-- Info is pointing here, "L1"
> >  #
> >  # Lorem Ipsum
> >  ##
> > ```
> >
> > would be transformed to rST as:
> >
> > ```
> > =======        <-- L1
> > Section        <-- L1
> > =======        <-- L1
> >                <-- L2
> > Lorem Ipsum    <-- L3
> > ```
>
> Not a demand, just wondering: could we drop our headings syntax and just
> use rST?
>

Yes, once we drop the old qapidoc fully, which I am not sure I can do
before freeze ... So we have some goofy stuff in the meantime.
You suggested before I can rewrite the freeform generator to avoid needing
this; I wrote the freeform generator to be as close to the old one as I
could, but we could kerjiggle it if needed.

... On the other hand, this is a patch for a += n, so... eh.

--js
Re: [PATCH 39/57] qapi/source: allow multi-line QAPISourceInfo advancing
Posted by Markus Armbruster 3 weeks, 6 days ago
John Snow <jsnow@redhat.com> writes:

> On Wed, Mar 5, 2025 at 5:35 AM Markus Armbruster <armbru@redhat.com> wrote:
>
>> John Snow <jsnow@redhat.com> writes:
>>
>> > This is for the sake of the new rST generator (the "transmogrifier") so
>> > we can advance multiple lines on occasion while keeping the
>> > generated<-->source mappings accurate.
>> >
>> > next_line now simply takes an optional n parameter which chooses the
>> > number of lines to advance.
>> >
>> > RFC: Here's the exorbitant detail on why I want this:
>> >
>> > This is used mainly when converting section syntax in free-form
>> > documentation to more traditional rST section header syntax, which
>> > does not always line up 1:1 for line counts.
>>
>> Obvious way to resolve the RFC:
>>
>>   The next patch will use this when converting ...
>>
>> >
>> > For example:
>> >
>> > ```
>> >  ##
>> >  # = Section     <-- Info is pointing here, "L1"
>> >  #
>> >  # Lorem Ipsum
>> >  ##
>> > ```
>> >
>> > would be transformed to rST as:
>> >
>> > ```
>> > =======        <-- L1
>> > Section        <-- L1
>> > =======        <-- L1
>> >                <-- L2
>> > Lorem Ipsum    <-- L3
>> > ```
>>
>> Not a demand, just wondering: could we drop our headings syntax and just
>> use rST?
>>
>
> Yes, once we drop the old qapidoc fully, which I am not sure I can do
> before freeze ... So we have some goofy stuff in the meantime.

No need to do it before the freeze.  Trying to do it before might be
self-sabotage ;)

> You suggested before I can rewrite the freeform generator to avoid needing
> this; I wrote the freeform generator to be as close to the old one as I
> could, but we could kerjiggle it if needed.
>
> ... On the other hand, this is a patch for a += n, so... eh.
>
> --js