示例#1
0
def happend(*args):
    '''Doc * Doc * ... -> Doc
    Concatenates argument (horizontaly)
    '''
    if not args:
        return empty()

    doc = args[-1]

    for arg in args[-2::-1]:
        doc = DocCat(arg, doc)

    return doc
示例#2
0
def happend_with(sep, *args):
    '''Doc * Doc * Doc * ... -> Doc
    Concatenates the argument, each one separated
    by the sep document
    '''
    if not args:
        return empty()
    size = len(args)
    if size == 1:
        return args[0]
    # at least 2 arguments
    nargs = []
    count = 0
    for arg in args:
        nargs.append(arg)
        if count < size - 1:
            nargs.append(sep)
        count = count + 1
    return happend(*nargs)
示例#3
0
 def f(n):
     if n > nb_spaces:
         return empty()
     else:
         return spaces(nb_spaces - n)