Esempio n. 1
0
    def parse(self, line):
        pctxt = self.pctxt

        result = re.search(r'(See also *:)', line)
        if result:
            label = result.group(0)

            desc = re.sub(r'.*See also *:', '', line).strip()

            indent = parser.get_indent(line)

            # Some descriptions are on multiple lines
            while pctxt.has_more_lines(1) and parser.get_indent(pctxt.get_line(1)) >= indent:
                desc += " " + pctxt.get_line(1).strip()
                pctxt.next()

            pctxt.eat_empty_lines()
            pctxt.next()
            pctxt.stop = True

            template = pctxt.templates.get_template("parser/seealso.tpl")
            return template.render(
                label=label,
                desc=desc,
            )

        return line
Esempio n. 2
0
    def parse(self, line):
        pctxt = self.pctxt

        result = re.search(r'(See also *:)', line)
        if result:
            label = result.group(0)

            desc = re.sub(r'.*See also *:', '', line).strip()

            indent = parser.get_indent(line)

            # Some descriptions are on multiple lines
            while pctxt.has_more_lines(1) and parser.get_indent(pctxt.get_line(1)) >= indent and pctxt.get_line(1).strip() != '':
                desc += " " + pctxt.get_line(1).strip()
                pctxt.next()

            pctxt.eat_empty_lines()
            pctxt.next()
            pctxt.stop = True

            template = pctxt.templates.get_template("parser/seealso.tpl")
            return template.render(
                pctxt=pctxt,
                label=label,
                desc=desc,
            )

        return line
Esempio n. 3
0
    def parse(self, line):
        #return re.sub(r'(Arguments *:)', self.replace, line)
        pctxt = self.pctxt

        result = re.search(r'(Arguments? *:)', line)
        if result:
            label = result.group(0)
            content = []

            desc_indent = False
            desc = re.sub(r'.*Arguments? *:', '', line).strip()

            indent = parser.get_indent(line)

            pctxt.next()
            pctxt.eat_empty_lines()

            arglines = []
            if desc != "none":
                add_empty_lines = 0
                while pctxt.has_more_lines() and (parser.get_indent(pctxt.get_line()) > indent):
                    for j in range(0, add_empty_lines):
                        arglines.append("")
                    arglines.append(pctxt.get_line())
                    pctxt.next()
                    add_empty_lines = pctxt.eat_empty_lines()
                    '''
                    print line

                    if parser.get_indent(line) == arg_indent:
                        argument = re.sub(r' *([^ ]+).*', r'\1', line)
                        if argument:
                            #content.append("<b>%s</b>" % argument)
                            arg_desc = [line.replace(argument, " " * len(self.unescape(argument)), 1)]
                            #arg_desc = re.sub(r'( *)([^ ]+)(.*)', r'\1<b>\2</b>\3', line)
                            arg_desc_indent = parser.get_indent(arg_desc[0])
                            arg_desc[0] = arg_desc[0][arg_indent:]
                            pctxt.next()
                            add_empty_lines = 0
                            while pctxt.has_more_lines and parser.get_indent(pctxt.get_line()) >= arg_indent:
                                for i in xrange(0, add_empty_lines):
                                    arg_desc.append("")
                                arg_desc.append(pctxt.get_line()[arg_indent:])
                                pctxt.next()
                                add_empty_lines = pctxt.eat_empty_lines()
                            # TODO : reduce space at the beginnning
                            content.append({
                                'name': argument,
                                'desc': arg_desc
                            })
                    '''

                if arglines:
                    new_arglines = []
                    #content = self.parse_args(arglines)
                    parser.remove_indent(arglines)
                    '''
                    pctxt2 = parser.PContext(pctxt.templates)
                    pctxt2.set_content_list(arglines)
                    while pctxt2.has_more_lines():
                        new_arglines.append(parser.example.Parser(pctxt2).parse(pctxt2.get_line()))
                        pctxt2.next()
                    arglines = new_arglines
                    '''

            pctxt.stop = True

            template = pctxt.templates.get_template("parser/arguments.tpl")
            return template.render(
                pctxt=pctxt,
                label=label,
                desc=desc,
                content=arglines
                #content=content
            )
            return line

        return line
Esempio n. 4
0
    def parse(self, line):
        pctxt = self.pctxt

        result = re.search(r'(Examples? *:)', line)
        if result:
            label = result.group(0)

            desc_indent = False
            desc = re.sub(r'.*Examples? *:', '', line).strip()

            # Some examples have a description
            if desc:
                desc_indent = len(line) - len(desc)

            indent = parser.get_indent(line)

            if desc:
                # And some description are on multiple lines
                while pctxt.get_line(1) and parser.get_indent(pctxt.get_line(1)) == desc_indent:
                    desc += " " + pctxt.get_line(1).strip()
                    pctxt.next()

            pctxt.next()
            add_empty_line = pctxt.eat_empty_lines()

            content = []

            if parser.get_indent(pctxt.get_line()) > indent:
                if desc:
                    desc = desc[0].upper() + desc[1:]
                add_empty_line = 0
                while pctxt.has_more_lines() and ((not pctxt.get_line()) or (parser.get_indent(pctxt.get_line()) > indent)):
                    if pctxt.get_line():
                        for j in xrange(0, add_empty_line):
                            content.append("")

                        content.append(re.sub(r'(#.*)$', self.comment, pctxt.get_line()))
                        add_empty_line = 0
                    else:
                        add_empty_line += 1
                    pctxt.next()
            elif parser.get_indent(pctxt.get_line()) == indent:
                # Simple example that can't have empty lines
                if add_empty_line:
                    # This means that the example was on the same line as the 'Example' tag
                    content.append(" " * indent + desc)
                    desc = False
                else:
                    while pctxt.has_more_lines() and (parser.get_indent(pctxt.get_line()) == indent):
                        content.append(pctxt.get_line())
                        pctxt.next()
                    pctxt.eat_empty_lines() # Skip empty remaining lines

            pctxt.stop = True

            parser.remove_indent(content)

            template = pctxt.templates.get_template("parser/example.tpl")
            return template.render(
                label=label,
                desc=desc,
                content=content
            )
        return line
Esempio n. 5
0
    def parse(self, line):
        #return re.sub(r'(Arguments *:)', self.replace, line)
        pctxt = self.pctxt

        result = re.search(r'(Arguments? *:)', line)
        if result:
            label = result.group(0)
            content = []

            desc_indent = False
            desc = re.sub(r'.*Arguments? *:', '', line).strip()

            indent = parser.get_indent(line)

            pctxt.next()
            pctxt.eat_empty_lines()

            arglines = []
            if desc != "none":
                add_empty_lines = 0
                while pctxt.has_more_lines() and (parser.get_indent(
                        pctxt.get_line()) > indent):
                    for j in range(0, add_empty_lines):
                        arglines.append("")
                    arglines.append(pctxt.get_line())
                    pctxt.next()
                    add_empty_lines = pctxt.eat_empty_lines()
                    '''
                    print line

                    if parser.get_indent(line) == arg_indent:
                        argument = re.sub(r' *([^ ]+).*', r'\1', line)
                        if argument:
                            #content.append("<b>%s</b>" % argument)
                            arg_desc = [line.replace(argument, " " * len(self.unescape(argument)), 1)]
                            #arg_desc = re.sub(r'( *)([^ ]+)(.*)', r'\1<b>\2</b>\3', line)
                            arg_desc_indent = parser.get_indent(arg_desc[0])
                            arg_desc[0] = arg_desc[0][arg_indent:]
                            pctxt.next()
                            add_empty_lines = 0
                            while pctxt.has_more_lines and parser.get_indent(pctxt.get_line()) >= arg_indent:
                                for i in xrange(0, add_empty_lines):
                                    arg_desc.append("")
                                arg_desc.append(pctxt.get_line()[arg_indent:])
                                pctxt.next()
                                add_empty_lines = pctxt.eat_empty_lines()
                            # TODO : reduce space at the beginnning
                            content.append({
                                'name': argument,
                                'desc': arg_desc
                            })
                    '''

                if arglines:
                    new_arglines = []
                    #content = self.parse_args(arglines)
                    parser.remove_indent(arglines)
                    '''
                    pctxt2 = parser.PContext(pctxt.templates)
                    pctxt2.set_content_list(arglines)
                    while pctxt2.has_more_lines():
                        new_arglines.append(parser.example.Parser(pctxt2).parse(pctxt2.get_line()))
                        pctxt2.next()
                    arglines = new_arglines
                    '''

            pctxt.stop = True

            template = pctxt.templates.get_template("parser/arguments.tpl")
            return template.render(pctxt=pctxt,
                                   label=label,
                                   desc=desc,
                                   content=arglines
                                   #content=content
                                   )
            return line

        return line
Esempio n. 6
0
    def parse(self, line):
        pctxt = self.pctxt

        result = re.search(r'^ *(Examples? *:)(.*)', line)
        if result:
            label = result.group(1)

            desc_indent = False
            desc = result.group(2).strip()

            # Some examples have a description
            if desc:
                desc_indent = len(line) - len(desc)

            indent = parser.get_indent(line)

            if desc:
                # And some description are on multiple lines
                while pctxt.get_line(1) and parser.get_indent(
                        pctxt.get_line(1)) == desc_indent:
                    desc += " " + pctxt.get_line(1).strip()
                    pctxt.next()

            pctxt.next()
            add_empty_line = pctxt.eat_empty_lines()

            content = []

            if parser.get_indent(pctxt.get_line()) > indent:
                if desc:
                    desc = desc[0].upper() + desc[1:]
                add_empty_line = 0
                while pctxt.has_more_lines() and (
                    (not pctxt.get_line()) or
                    (parser.get_indent(pctxt.get_line()) > indent)):
                    if pctxt.get_line():
                        for j in range(0, add_empty_line):
                            content.append("")

                        content.append(
                            re.sub(r'(#.*)$', self.comment, pctxt.get_line()))
                        add_empty_line = 0
                    else:
                        add_empty_line += 1
                    pctxt.next()
            elif parser.get_indent(pctxt.get_line()) == indent:
                # Simple example that can't have empty lines
                if add_empty_line and desc:
                    # This means that the example was on the same line as the 'Example' tag
                    # and was not a description
                    content.append(" " * indent + desc)
                    desc = False
                else:
                    while pctxt.has_more_lines() and (parser.get_indent(
                            pctxt.get_line()) >= indent):
                        content.append(pctxt.get_line())
                        pctxt.next()
                    pctxt.eat_empty_lines()  # Skip empty remaining lines

            pctxt.stop = True

            parser.remove_indent(content)

            template = pctxt.templates.get_template("parser/example.tpl")
            return template.render(pctxt=pctxt,
                                   label=label,
                                   desc=desc,
                                   content=content)
        return line