How to use the ford.utils.paren_split function in FORD

To help you get started, we’ve selected a few FORD examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif tmp_attribs[i].lower() == "parameter": parameter = True
            elif tmp_attribs[i].lower().replace(' ','') == "intent(in)":
                intent = 'in'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(out)":
                intent = 'out'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(inout)":
                intent = 'inout'
            else: attribs.append(tmp_attribs[i])
    else:
        declarestr = ATTRIBSPLIT2_RE.match(rest).group(2)
    declarations = ford.utils.paren_split(",",declarestr)

    varlist = []
    for dec in declarations:
        dec = re.sub(" ","",dec)
        split = ford.utils.paren_split('=',dec)
        if len(split) > 1:
            name = split[0]
            if split[1][0] == '>':
                initial = split[1][1:]
                points = True
            else:
                initial = split[1]
                points = False
        else:
            name = dec.strip()
            initial = None
            points = False

        if initial:
            initial = COMMA_RE.sub(', ',initial)
            search_from = 0
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif attr == 'dimension' or attr == 'allocatable' or attr == 'pointer':
                        names = ford.utils.paren_split(',',match.group(2))
                        for name in names:
                            name = name.strip().lower()
                            i = name.index('(')
                            n = name[:i]
                            sh = name[i:]
                            if n in self.attr_dict:
                                self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
                            num = int(QUOTES_RE.search(attr[search_from:]).group()[1:-1])
                            attr = attr[0:search_from] + QUOTES_RE.sub(self.strings[num],attr[search_from:],count=1)
                            search_from += QUOTES_RE.search(attr[search_from:]).end(0)
                        for name in names:
                            if attr == 'parameter':
                                split = ford.utils.paren_split('=',name)
                                name = split[0].strip().lower()
                                self.param_dict[name] = split[1]
                            name = name.strip().lower()
                            if name in self.attr_dict:
                                self.attr_dict[name].append(attr)
                            else:
                                self.attr_dict[name] = [attr]
                elif attr.lower() == 'data' and self.obj == 'sourcefile':
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
def _initialize(self,line):
        self.name = line.group(1)
        if not self.name: self.name = ''
        self.other_uses = []
        self.variables = [v.strip() for v in ford.utils.paren_split(',',line.group(2))]
        self.visible = True
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif attr == 'dimension' or attr == 'allocatable' or attr == 'pointer':
                        names = ford.utils.paren_split(',',match.group(2))
                        for name in names:
                            name = name.strip().lower()
                            i = name.index('(')
                            n = name[:i]
                            sh = name[i:]
                            if n in self.attr_dict:
                                self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
                            num = int(QUOTES_RE.search(attr[search_from:]).group()[1:-1])
                            attr = attr[0:search_from] + QUOTES_RE.sub(self.strings[num],attr[search_from:],count=1)
                            search_from += QUOTES_RE.search(attr[search_from:]).end(0)
                        for name in names:
                            if attr == 'parameter':
                                split = ford.utils.paren_split('=',name)
                                name = split[0].strip().lower()
                                self.param_dict[name] = split[1]
                            name = name.strip().lower()
                            if name in self.attr_dict:
                                self.attr_dict[name].append(attr)
                            else:
                                self.attr_dict[name] = [attr]
                elif attr.lower() == 'data' and self.obj == 'sourcefile':
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
                            num = int(QUOTES_RE.search(attr[search_from:]).group()[1:-1])
                            attr = attr[0:search_from] + QUOTES_RE.sub(self.strings[num],attr[search_from:],count=1)
                            search_from += QUOTES_RE.search(attr[search_from:]).end(0)
                        for name in names:
                            if attr == 'parameter':
                                split = ford.utils.paren_split('=',name)
                                name = split[0].strip().lower()
                                self.param_dict[name] = split[1]
                            name = name.strip().lower()
                            if name in self.attr_dict:
                                self.attr_dict[name].append(attr)
                            else:
                                self.attr_dict[name] = [attr]
                elif attr.lower() == 'data' and self.obj == 'sourcefile':
                    # TODO: This is just a fix to keep FORD from crashing on encountering a block data structure. At some point I should actually implement support for them.
                    continue
                else:
                    raise Exception("Found {} statement in {}".format(attr.upper(),type(self).__name__[7:].upper()))
            elif self.END_RE.match(line):
                if isinstance(self,FortranSourceFile):
                    raise Exception("END statement outside of any nesting")
                endtype = self.END_RE.match(line).group(1)
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
raise Exception("CONTAINS statement in {}".format(type(self).__name__[7:].upper()))
            elif line.lower() == "public": permission = "public"
            elif line.lower() == "private": permission = "private"
            elif line.lower() == "protected": permission = "protected"
            elif line.lower() == "sequence":
                if type(self) == FortranType: self.sequence = True
            elif self.ATTRIB_RE.match(line) and blocklevel == 0:
                match = self.ATTRIB_RE.match(line)
                attr = match.group(1).lower().replace(" ", "")
                if len(attr) >= 4 and attr[0:4].lower() == 'bind':
                    attr = attr.replace(",",", ")
                if hasattr(self,'attr_dict'):
                    if attr == 'data':
                        pass
                    elif attr == 'dimension' or attr == 'allocatable' or attr == 'pointer':
                        names = ford.utils.paren_split(',',match.group(2))
                        for name in names:
                            name = name.strip().lower()
                            i = name.index('(')
                            n = name[:i]
                            sh = name[i:]
                            if n in self.attr_dict:
                                self.attr_dict[n].append(attr+sh)
                            else:
                                self.attr_dict[n] = [attr+sh]
                    else:
                        stmnt = match.group(2)
                        if attr == 'parameter':
                            stmnt = stmnt[1:-1].strip()
                        names = ford.utils.paren_split(',',stmnt)
                        search_from = 0
                        while QUOTES_RE.search(attr[search_from:]):
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
"""
    Returns a list of variables declared in the provided line of code. The
    line of code should be provided as a string.
    """
    vartype, kind, strlen, proto, rest = parse_type(line,parent.strings,parent.settings)
    attribs = []
    intent = ""
    optional = False
    permission = inherit_permission
    parameter = False

    attribmatch = ATTRIBSPLIT_RE.match(rest)
    if attribmatch:
        attribstr = attribmatch.group(1).strip()
        declarestr = attribmatch.group(2).strip()
        tmp_attribs = ford.utils.paren_split(",",attribstr)
        for i in range(len(tmp_attribs)):
            tmp_attribs[i] = tmp_attribs[i].strip()
            if tmp_attribs[i].lower() == "public": permission = "public"
            elif tmp_attribs[i].lower() == "private": permission = "private"
            elif tmp_attribs[i].lower() == "protected": permission = "protected"
            elif tmp_attribs[i].lower() == "optional": optional = True
            elif tmp_attribs[i].lower() == "parameter": parameter = True
            elif tmp_attribs[i].lower().replace(' ','') == "intent(in)":
                intent = 'in'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(out)":
                intent = 'out'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(inout)":
                intent = 'inout'
            else: attribs.append(tmp_attribs[i])
    else:
        declarestr = ATTRIBSPLIT2_RE.match(rest).group(2)
github Fortran-FOSS-Programmers / ford / ford / sourceform.py View on Github external
elif tmp_attribs[i].lower() == "parameter": parameter = True
            elif tmp_attribs[i].lower().replace(' ','') == "intent(in)":
                intent = 'in'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(out)":
                intent = 'out'
            elif tmp_attribs[i].lower().replace(' ','') == "intent(inout)":
                intent = 'inout'
            else: attribs.append(tmp_attribs[i])
    else:
        declarestr = ATTRIBSPLIT2_RE.match(rest).group(2)
    declarations = ford.utils.paren_split(",",declarestr)

    varlist = []
    for dec in declarations:
        dec = re.sub(" ","",dec)
        split = ford.utils.paren_split('=',dec)
        if len(split) > 1:
            name = split[0]
            if split[1][0] == '>':
                initial = split[1][1:]
                points = True
            else:
                initial = split[1]
                points = False
        else:
            name = dec.strip()
            initial = None
            points = False

        if initial:
            initial = COMMA_RE.sub(', ',initial)
            search_from = 0