sed-devel
[Top][All Lists]
Advanced

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

Re: proposed features for branching logic + minimal implementation


From: Liam Quinlan
Subject: Re: proposed features for branching logic + minimal implementation
Date: Sun, 1 Nov 2020 12:33:47 -0500

In case there's still interest for examples, I ended up writing a
pretty-print script to help with reading GCC spec files.  It's not model
code or anything, just something hacked together, but it does shows some
real use.
Here's the script:

````
     sed -rn '/^[*]/{ :0; N; s/\n$//; T0; s/\n/\t/g; s/$/\n/p; }' |
     sed -rn '{
                :b;  s/([^%\{#])[\{]/\1#\{\n####:\n/;
                     @{
                      :B;
 s/([\{\}])(\n####[:-]+\n)([^\{\}]*[\{\}])/\1\3\2/;
                           @!{
                                 l;s/$/\nerror! (no next brace?)/p;
                                 =;q;
                           };

                           s/([\{]\n####[:-]+)\n/\1-\n/;
                           @{
                                 s/([^%#])([\{]\n####[:-]*)-\n/\1#\2:\n/;
                                 J;
                                 bB;
                           };

                           s/([\}]\n####[:-]*):\n/#\1\n/;
                           @{
                                 s/#[\}]\n####\n/#\}/;
                                 tb;
                                 bB;
                           };

                           s/([\}]\n####[:-]+)-\n/\1\n/;
                           @!{
                                 l;s/$/\nerror! (brace count wrong?)/p;
                                 =;q;
                           };
                           bB;
                     };


                     x;
                       s/.*/\t/; J;
                       H;
                     x;
                     s/^(%[\{])/ \1/;

                :0;  s/^([^%#\}]([^%#\}]|%[^\{\}]|#.)*)[
\t]*(%[\{].*)\n([\t]+)$/\1\n\4#\3/;
                     @{
                          s/^/~/;
                          x;
                            s/^/\t/; J;
                            H;
                          x;
                          b0;
                     };

                :1;
 s/(#%[\{]([^#%\}]|#[^#]|%[^\{\}])*)[\}](.*)\n[\t]?([\t]*)$/\1\n\4#\}\n\4\3/;
                     @{
                          s/^~//;
                          @{
                               x;
                                 s/^\t//; J;
                                 H;
                               x;
                               b1;
                          };{
                               s/\n\t*#[\}]\n\t*(([^#]|#[^\}])*)$/#\}\1/; J;
                               G;
                               b1;
                          };
                      };

                     s/([^#](%[\{]|[\}]))/\1/;
                     t0;

                     s/^~*//;
                     s/\n[\t]*$//;
                     s/#//g;
                     s/[\t]/    /g;
                     s/(%[\{][^\}\n]*) *\n *[\}]\n/\1\}/g;
                     s/([^ \t\n])[ ]{4,}([^ \t\n])/\1   \2/g;
                     p;
    }'
````

in case you want to see what it's doing, here's some pastebin: (before and
after, feeding it my WSL box's distro defaults)
https://pastebin.com/KRv9mmMg
https://pastebin.com/GMnt65Hz


On Thu, Oct 8, 2020 at 12:05 AM Assaf Gordon <assafgordon@gmail.com> wrote:

> Hello,
>
> On 2020-10-06 4:47 p.m., Liam Quinlan wrote:
> > I would like to propose four related additions to the sed toolbox
> > (represented below, arbitrarily, as '@', 'k', 'j', and 'J').  In my
> > opinion, these additions improve sed's usability near one of its
> > weaknesses (restricted branching logic), and represent a solid value
> > proposition in light of their minor code change requirements.
>
> Thank you for this suggestion and for providing the code - that's an
> excellent start.
>
> For any contribution to be incorporated into GNU sed
> (or even evaluated / considered), we first ask the contributor to assign
> copyright of the code to the FSF.
>
> You can read more about it here:
>    https://www.gnu.org/licenses/why-assign.en.html
>    https://www.fsf.org/licensing/assigning.html
>
> To start the process, please fill and send the following form:
>
>
> https://git.savannah.gnu.org/cgit/gnulib.git/plain/doc/Copyright/request-assign.future
>
> ---
>
> Now to the actual patch:
> Looks interested, but may I ask for some specific use cases where each
> short-hand command would be used, and be a clear improvement over the
> existing commands ?
>
> regards,
>   - assaf
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]