Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
DarianDeGraaf authored Jun 11, 2024
1 parent 6f5c869 commit 1c4e0a8
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions lizard_languages/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,31 @@
from .code_reader import CodeStateMachine, CodeReader



branch_coverage = {
"fortran_01" : False,
"fortran_02" : False,
"fortran_03" : False,
"fortran_04" : False,
"fortran_05" : False,
"fortran_06" : False,
"fortran_07" : False,
"fortran_08" : False,
"fortran_09" : False,
"fortran_10" : False,
"fortran_11" : False,
"fortran_12" : False,
"fortran_13" : False,
"fortran_14" : False,
"fortran_15" : False,
"fortran_16" : False
}

def print_coverage():
for branch, hit in branch_coverage.items():
print(f"{branch} was {'hit' if hit else 'not hit'}")


# pylint: disable=R0903
class FortranCommentsMixin(object):
@staticmethod
Expand Down Expand Up @@ -98,34 +123,48 @@ def __call__(self, token, reader=None):
def _state_global(self, token):
token_upper = token.upper()
if token_upper in ('%', '::', 'SAVE', 'DATA'):
branch_coverage["fortran_01"] = True
self._state = self._ignore_next
elif token_upper in ('INTEGER', 'REAL','COMPLEX','LOGICAL', 'CHARACTER'):
self._state = self._ignore_var
branch_coverage["fortran_02"] = True
elif token == '(':
branch_coverage["fortran_03"] = True
self.next(self._ignore_expr, token)
elif token_upper in ('PROGRAM',):
branch_coverage["fortran_04"] = True
self._state = self._namespace
elif token_upper == 'MODULE':
branch_coverage["fortran_05"] = True
self._state = self._module
elif token_upper in ('SUBROUTINE', 'FUNCTION'):
branch_coverage["fortran_06"] = True
self._state = self._function_name
elif token_upper == 'TYPE':
branch_coverage["fortran_07"] = True
self._state = self._type
elif token_upper == 'IF':
branch_coverage["fortran_08"] = True
self._state = self._if
elif token_upper in ('BLOCK',):
branch_coverage["fortran_09"] = True
self._state = self._ignore_if_paren
elif token_upper in ('DO',):
branch_coverage["fortran_10"] = True
self._state = self._ignore_if_label
elif token_upper in ('FORALL', 'WHERE', 'SELECT', 'INTERFACE', 'ASSOCIATE'):
branch_coverage["fortran_11"] = True
self.context.add_bare_nesting()
elif token_upper == 'ELSE':
branch_coverage["fortran_12"] = True
self.context.pop_nesting()
self.context.add_bare_nesting()
elif token_upper.replace(' ', '') == 'ELSEIF':
branch_coverage["fortran_13"] = True
self.context.pop_nesting()
self._state = self._if
elif token_upper == 'END' or self._ends.match(token):
branch_coverage["fortran_14"] = True
self.context.pop_nesting()

def reset_state(self, token=None):
Expand All @@ -145,8 +184,10 @@ def _ignore_var(self, token):

def _ignore_if_paren(self, token):
if token == '(':
branch_coverage["fortran_15"] = True
self.next(self._ignore_expr, token)
else:
branch_coverage["fortran_16"] = True
self.context.add_bare_nesting()
self.reset_state()

Expand Down

0 comments on commit 1c4e0a8

Please sign in to comment.