Skip to content

Commit c13e447

Browse files
committed
Minor improvements
- Removes self.line - Improves funcion names
1 parent d2ff31a commit c13e447

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

fortls/parse_fortran.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ def __init__(self, path: str = None, pp_suffixes: list = None):
818818
self.preproc: bool = False
819819
self.ast: fortran_ast = None
820820
self.hash: str = None
821-
self.line: str = None
822821
if path:
823822
_, file_ext = os.path.splitext(os.path.basename(path))
824823
if pp_suffixes:
@@ -1303,17 +1302,16 @@ def parse(
13031302
multi_lines.extendleft(line_stripped.split(";"))
13041303
line = multi_lines.pop()
13051304
line_stripped = line
1306-
self.line = line
13071305
# Test for scope end
13081306
if file_ast.END_SCOPE_REGEX is not None:
13091307
match = FRegex.END_WORD.match(line_no_comment)
13101308
# Handle end statement
1311-
if self._parse_end_scope_word(
1309+
if self.parse_end_scope_word(
13121310
line_no_comment, line_number, file_ast, match
13131311
):
13141312
continue
13151313
# Look for old-style end of DO loops with line labels
1316-
if self._parse_do_fixed_format(
1314+
if self.parse_do_fixed_format(
13171315
line, line_number, file_ast, line_label, block_id_stack
13181316
):
13191317
continue
@@ -1638,10 +1636,27 @@ def parse(
16381636
log.debug(f"{error['range']}: {error['message']}")
16391637
return file_ast
16401638

1641-
def _parse_end_scope_word(
1639+
def parse_end_scope_word(
16421640
self, line: str, ln: int, file_ast: fortran_ast, match: re.Match
1643-
):
1644-
# TODO: line.strip() is the normal line, make it self.line
1641+
) -> bool:
1642+
"""Parses END keyword marking the end of scopes
1643+
1644+
Parameters
1645+
----------
1646+
line : str
1647+
Document line
1648+
ln : int
1649+
Line number
1650+
file_ast : fortran_ast
1651+
AST object
1652+
match : re.Match
1653+
END word regular expression match
1654+
1655+
Returns
1656+
-------
1657+
bool
1658+
True if a AST scope is closed, False otherwise
1659+
"""
16451660
if match is None:
16461661
return False
16471662

@@ -1666,7 +1681,7 @@ def _parse_end_scope_word(
16661681
return True
16671682
return False
16681683

1669-
def _parse_do_fixed_format(
1684+
def parse_do_fixed_format(
16701685
self,
16711686
line: str,
16721687
ln: int,
@@ -1683,7 +1698,7 @@ def _parse_do_fixed_format(
16831698
file_ast.end_scope(ln)
16841699
block_id_stack.pop()
16851700
did_close = True
1686-
self.parser_debug("DO", self.line, ln, scope=True)
1701+
self.parser_debug("DO", line, ln, scope=True)
16871702
if did_close:
16881703
return True
16891704
return False
@@ -1701,7 +1716,7 @@ def _parse_implicit(self, line: str, ln: int, file_ast: fortran_ast):
17011716
else:
17021717
file_ast.current_scope.set_implicit(True, ln)
17031718

1704-
self.parser_debug("IMPLICIT", self.line, ln)
1719+
self.parser_debug("IMPLICIT", line, ln)
17051720
return True
17061721

17071722
def _parse_contains(self, line: str, ln: int, file_ast: fortran_ast):
@@ -1718,7 +1733,7 @@ def _parse_contains(self, line: str, ln: int, file_ast: fortran_ast):
17181733
msg = "Multiple CONTAINS statements in scope"
17191734
if msg:
17201735
file_ast.add_error(msg, Severity.error, ln, match.start(1), match.end(1))
1721-
self.parser_debug("CONTAINS", self.line, ln)
1736+
self.parser_debug("CONTAINS", line, ln)
17221737
return True
17231738

17241739
def parse_docs(self, line: str, ln: int, file_ast: fortran_ast, docs: list[str]):

0 commit comments

Comments
 (0)