def label()

in src/composer/composer.py [0:0]


def label(composition):
    ''' recursively label combinators with the json path '''
    def label(path):
        def labeler(composition, name=None, array=False):
            nonlocal path
            segment = ''
            if name is not None:
                if array:
                    segment = '['+name+']'
                else:
                    segment = '.'+name

            p = path + segment
            composition = visit(composition, label(p))
            composition.path = p
            return composition

        return labeler

    return label('')(composition)