[PATCH v2] releasenotes: improve parsing around bullet points

Yuya Nishihara yuya at tcha.org
Mon Jun 19 09:26:22 EDT 2017


On Tue, 13 Jun 2017 22:38:21 +0200, Rishabh Madan wrote:
> # HG changeset patch
> # User Rishabh Madan <rishabhmadan96 at gmail.com>
> # Date 1497386167 -7200
> #      Tue Jun 13 22:36:07 2017 +0200
> # Node ID 15c645861efc09cf79cf1c0c6f59cbf8ad1a34c7
> # Parent  6675d23da74855a350a8b2dc54166d0b345576da
> releasenotes: improve parsing around bullet points

Sorry for the delay. I did some hacks by myself to understand how parsing
works, and a couple of questions came in.

> +    def gatherbullets(offset):
> +        bullet_points = []
> +
> +        for i in range(offset + 1, len(blocks)):
> +            block = blocks[i]
> +
> +            if block['type'] == 'margin':
> +                continue
> +            elif block['type'] == 'section':
> +                break
> +            elif block['type'] == 'bullet':
> +                if block['indent'] != 0:
> +                    raise error.Abort(_('indented bullet lists not supported'))
> +
> +                lines = [[l[1:].strip() for l in block['lines']]]

This function is quite similar to gatherparagraphs(). So maybe the
postprocessing of bullet blocks could be factored out to a function.

> +                if i < len(blocks) - 1:
> +                    i += 1
> +                    block = blocks[i]
> +                    if block['type']=='paragraph':
> +                        lines.append(block['lines'])
> +
> +                    while block['type'] != 'bullet' and i < len(blocks) - 1:
> +                        if block['type'] == 'section':
> +                            break
> +                        i += 1
> +                        block = blocks[i]
> +                        if block['type'] == 'paragraph':
> +                            lines.append(block['lines'])
> +                bullet_points.append(lines)
> +                continue
> +            elif block['type'] != 'paragraph':
> +                raise error.Abort(_('unexpected block type in release notes: '
> +                                    '%s') % block['type'])
> +        return bullet_points
> +
>      def gatherparagraphs(offset):
>          paragraphs = []
>  
> @@ -226,16 +261,18 @@
>                                    title)
>  
>              currentsection = name
> -            paragraphs = gatherparagraphs(i)
> -            if paragraphs:
> -                notes.addnontitleditem(currentsection, paragraphs)
> +            bullet_points = gatherbullets(i)
> +            if bullet_points:
> +                for para in bullet_points:
> +                    notes.addnontitleditem(currentsection, para)

Don't we need to process both paragraphs and bullet points here? I guess we'll
need a function that gathers both paragraphs and bullets in order of
appearance.

> +        if len(notes.nontitledforsection(section)) > 0:
> +            ui.write(_('  bullet point:\n'))
>          for paragraphs in notes.nontitledforsection(section):
> -            ui.write(_('  bullet point:\n'))
>              for para in paragraphs:
>                  ui.write(_('    paragraph: %s\n') % ' '.join(para))

I think 'bullet point:' should be printed per item. Otherwise we can't see if
paragraphs belong to one bullet point or not.


More information about the Mercurial-devel mailing list