def parse_line()

in src/advisor/parsers/naive_function_parser.py [0:0]


    def parse_line(self, line):
        """Parse function declarations in a source line.
        Multi-line declarations are supported so long as the follow the template:

        int
        myfunction
        (args)
        {

        Args:
            line (str): The line to parse.

        Returns:
            str: Current function name.
        """
        ret = None
        line = line.strip()
        if line.startswith('(') and self.previous_line:
            # function name is on previous line.
            function_line = self.previous_line + line
        elif line.startswith(')') and self.previous_line:
            # close of argument list
            function_line = self.previous_line + line
        elif line == '{' and self.previous_line:
            # opening brace is on its own line
            function_line = self.previous_line + line
        elif self.previous_line and (self.previous_line.endswith('(') or self.previous_line.endswith(',')):
            # multi line arguments
            function_line = self.previous_line + line
        elif self.previous_line and NaiveFunctionParser.TYPE_RE_PROG.search(self.previous_line):
            # multi line return type
            function_line = self.previous_line + ' ' + line
        else:
            function_line = line
        if len(function_line) < 1000: # length check to prevent running regexp on over-long lines
            match = NaiveFunctionParser.FUNCTION_RE_PROG.search(function_line)
        else:
            match = None
        if match and not match.group(1) in NaiveFunctionParser.KEYWORDS:
            ret = self.current_function = match.group(1)
            self.nesting = 1
            self.previous_line = None
        elif line.lstrip().startswith('{') or line.rstrip().endswith('{'):
            self.nesting += 1
        if line.lstrip().startswith('}') or line.rstrip().endswith('}'):
            self.nesting -= 1
        if self.nesting <= 0:
            self.nesting = 0
            self.current_function = None
        self.previous_line = function_line
        return ret