Esempio n. 1
0
    def examine_fortran(self, subject: FortranSource) -> List[Issue]:
        issues = []

        for statement in subject.find_all(Fortran2003.Use_Stmt):
            print ("statement = ", statement)
        for statement in subject.find_all(Fortran2003.Data_Component_Def_Stmt):
            print ("statement = ", statement)
        for statement in subject.find_all(Fortran2003.Proc_Component_Def_Stmt):
            print ("statement = ", statement)
        for statement in subject.find_all(Fortran2003.Procedure_Declaration_Stmt):
            print ("statement = ", statement)
        for statement in subject.find_all(Fortran2003.Type_Declaration_Stmt):
            print ("statement = ", statement)
        print ("text = ", subject.get_text())
        return issues
Esempio n. 2
0
    def examine(self, subject: FortranSource) -> List[Issue]:
        # pylint: disable=too-many-branches
        """
        Examines the source code for none Fortran characters.

        This is complicated by the fact that the source must consist of only
        certain characters except comments and strings. These may contain
        anything.
        """
        issues = super(FortranCharacterset, self).examine(subject)

        text = subject.get_text()
        index = 0
        line = 1
        state = 'code'
        while index < len(text):
            character = text[index]
            if state == 'code':
                if character == self._NEWLINE:
                    line += 1
                elif character == self._EXCLAMATION:
                    state = 'comment'
                elif character == self._APOSTROPHY:
                    state = 'apostraphystring'
                elif character == self._QUOTE:
                    state = 'quotestring'
                elif character in self._FORTRAN_CHARACTERSET:
                    pass
                else:
                    description = "Found character {char} " \
                                  + "not in Fortran character set"
                    description = description.format(char=repr(character))
                    issues.append(Issue(description, line=line))
            elif state == 'comment':
                if character == self._NEWLINE:
                    line += 1
                    state = 'code'
            elif state == 'apostraphystring':
                if character == self._APOSTROPHY:
                    state = 'code'
            elif state == 'quotestring':
                if character == self._QUOTE:
                    state = 'code'
            else:
                raise Exception('Parser in unknown state: ' + state)
            index += 1

        return issues
Esempio n. 3
0
    def examine(self, subject: FortranSource) -> List[Issue]:
        # pylint: disable=too-many-branches
        """
        Examines the source code for none Fortran characters.

        This is complicated by the fact that the source must consist of only
        certain characters except comments and strings. These may contain
        anything.
        """
        issues = super(FortranOldComparisons, self).examine(subject)

        text = subject.get_text()
        index = 0
        line = 1
        state = 'code'
        while index < len(text) - 4:
            characters = text[index:index + 4]
            if state == 'code':
                if characters[0] == self._NEWLINE:
                    line += 1
                elif characters[0] == self._EXCLAMATION:
                    state = 'comment'
                elif characters[0] == self._APOSTROPHY:
                    state = 'apostraphystring'
                elif characters[0] == self._QUOTE:
                    state = 'quotestring'
                elif characters == ".eq." or characters == ".ne." or characters == ".gt." or characters == ".lt." or characters == ".ge." or characters == ".le.":
                    description = "Found " + characters
                    issues.append(Issue(description, line=line))
                elif characters[0] in self._FORTRAN_CHARACTERSET:
                    pass
            elif state == 'comment':
                if characters[0] == self._NEWLINE:
                    line += 1
                    state = 'code'
            elif state == 'apostraphystring':
                if characters[0] == self._APOSTROPHY:
                    state = 'code'
            elif state == 'quotestring':
                if characters[0] == self._QUOTE:
                    state = 'code'
            else:
                raise Exception('Parser in unknown state: ' + state)
            index += 1

        return issues
Esempio n. 4
0
    def examine_fortran(self, subject: FortranSource) -> List[Issue]:
        issues = []

        text = subject.get_text()
        index = 0
        line = 1
        state = 'code'
        while index < len(text):
            character = text[index]
            if character == self._NEWLINE:
                line += 1
            elif character in self._FORTRAN_CHARACTERSET:
                pass
            else:
                description = "Found tab"
                issues.append(Issue(description, line=line))
            index += 1
        return issues
    def test_constructor(self) -> None:
        """
        Checks that the source file is correctly parsed on construction.
        """
        inject = r"""! Test program
program test
  implicit none
  write(6, '("Hello ", A)') 'world'
end program test
"""
        reader = SourceStringReader(inject)
        unit_under_test = FortranSource(reader)
        assert unit_under_test.get_text() == inject

        expected_string = """! Test program
PROGRAM test
  IMPLICIT NONE
  WRITE(6, FMT = '("Hello ", A)') 'world'
END PROGRAM test"""
        assert str(unit_under_test.get_tree()) == expected_string
Esempio n. 6
0
    def test_constructor(self):
        '''
        Checks that the source file is correctly parsed on construction.
        '''
        # pylint: disable=no-self-use
        inject = r'''! Test program
program test
  implicit none
  write(6, '("Hello ", A)') 'world'
end program test
'''
        reader = SourceStringReader(inject)
        unit_under_test = FortranSource(reader)
        assert unit_under_test.get_text() == inject

        expected_string = '''! Test program
PROGRAM test
  IMPLICIT NONE
  WRITE(6, FMT = '("Hello ", A)') 'world'
END PROGRAM test'''
        assert str(unit_under_test.get_tree()) == expected_string
Esempio n. 7
0
    def examine(self, subject: FortranSource) -> List[Issue]:
        issues = []

        text = subject.get_text()
        index = 0
        line = 1
        state = 'code'
        while index < len(text):
            character = text[index]
            if state == 'code':
                if character == self._NEWLINE:
                    line += 1
                elif character == self._EXCLAMATION:
                    state = 'comment'
                elif character == self._APOSTROPHY:
                    state = 'apostraphystring'
                elif character == self._QUOTE:
                    state = 'quotestring'
                elif character in self._FORTRAN_CHARACTERSET:
                    pass
                else:
                    description = "Found character {char} " \
                                  + "not in Fortran character set"
                    description = description.format(char=repr(character))
                    issues.append(Issue(description, line=line))
            elif state == 'comment':
                if character == self._NEWLINE:
                    line += 1
                    state = 'code'
            elif state == 'apostraphystring':
                if character == self._APOSTROPHY:
                    state = 'code'
            elif state == 'quotestring':
                if character == self._QUOTE:
                    state = 'code'
            else:
                raise Exception('Parser in unknown state: ' + state)
            index += 1

        return issues