Skip to content

Commit

Permalink
fix the elseif statement for fortran
Browse files Browse the repository at this point in the history
  • Loading branch information
terryyin committed Oct 31, 2024
1 parent 00e1009 commit ff1928b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions lizard_languages/fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,10 @@ def generate_tokens(source_code, addition='', token_class=None):
_until_end = r'(?:\\\n|[^\n])*'
return CodeReader.generate_tokens(
source_code,
r'(?i)' +
r'|\/\/' +
r'(?i)'
r'\/\/' +
r'|\#' + _until_end +
r'|\!' + _until_end +
r'|^C' + _until_end +
r'|^\*' + _until_end +
r'|\.OR\.' +
r'|\.AND\.' +
Expand Down Expand Up @@ -124,6 +123,8 @@ def _state_global(self, token):
self.context.add_bare_nesting()
elif token_upper.replace(' ', '') == 'ELSEIF':
self.context.pop_nesting()
if token_upper == 'ELSEIF':
self.context.add_condition()
self._state = self._if
elif token_upper == 'END' or self._ends.match(token):
self.context.pop_nesting()
Expand Down
15 changes: 15 additions & 0 deletions test/test_languages/testFortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,3 +185,18 @@ def test_macro_branched(self):
self.assertEqual(2, len(result))
self.assertEqual('test', result[0].name)
self.assertEqual('test7', result[1].name)

def test_case_insensitive_tokens(self):
'''Test that tokens are matched case-insensitively'''
result = get_fortran_function_list('''
subroutine test
If (a) Then
CALL sub(a)
elseIF (b) THEN
call SUB(b)
END IF
ENDsubroutine test
''')
self.assertEqual(1, len(result))
self.assertEqual('test', result[0].name)
self.assertEqual(2, result[0].cyclomatic_complexity)

0 comments on commit ff1928b

Please sign in to comment.