Skip to content

Commit 5a68e75

Browse files
committed
Updates contains parsing and formats
1 parent baa87fe commit 5a68e75

File tree

1 file changed

+45
-31
lines changed

1 file changed

+45
-31
lines changed

fortls/parse_fortran.py

Lines changed: 45 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,9 +1306,7 @@ def parse(
13061306
if file_ast.END_SCOPE_REGEX is not None:
13071307
match = FRegex.END_WORD.match(line_no_comment)
13081308
# Handle end statement
1309-
if self.parse_end_scope_word(
1310-
line_no_comment, line_no, file_ast, match
1311-
):
1309+
if self.parse_end_scope_word(line_no_comment, line_no, file_ast, match):
13121310
continue
13131311
# Look for old-style end of DO loops with line labels
13141312
if self.parse_do_fixed_format(
@@ -1323,7 +1321,7 @@ def parse(
13231321
if self._parse_implicit(line_no_comment, line_no, file_ast):
13241322
continue
13251323
# Mark contains statement
1326-
if self._parse_contains(line_no_comment, line_no, file_ast):
1324+
if self.parse_contains(line_no_comment, line_no, file_ast):
13271325
continue
13281326
# Loop through tests
13291327
obj_read = self.get_fortran_definition(line)
@@ -1343,7 +1341,7 @@ def parse(
13431341
if file_ast.current_scope.get_type() == INTERFACE_TYPE_ID:
13441342
for var_name in obj_info.var_names:
13451343
file_ast.add_int_member(var_name)
1346-
log.debug('%s !!! INTERFACE-PRO - Ln:%d', line.strip(), line_no)
1344+
log.debug("%s !!! INTERFACE-PRO - Ln:%d", line.strip(), line_no)
13471345
continue
13481346
procedure_def = True
13491347
link_name = get_paren_substring(desc_string)
@@ -1409,24 +1407,24 @@ def parse(
14091407

14101408
# if not merge_external:
14111409
file_ast.add_variable(new_var)
1412-
log.debug('%s !!! VARIABLE - Ln:%d', line, line_no)
1410+
log.debug("%s !!! VARIABLE - Ln:%d", line, line_no)
14131411

14141412
elif obj_type == "mod":
14151413
new_mod = fortran_module(file_ast, line_no, obj_info)
14161414
file_ast.add_scope(new_mod, FRegex.END_MOD)
1417-
log.debug('%s !!! MODULE - Ln:%d', line, line_no)
1415+
log.debug("%s !!! MODULE - Ln:%d", line, line_no)
14181416

14191417
elif obj_type == "smod":
14201418
new_smod = fortran_submodule(
14211419
file_ast, line_no, obj_info.name, ancestor_name=obj_info.parent
14221420
)
14231421
file_ast.add_scope(new_smod, FRegex.END_SMOD)
1424-
log.debug('%s !!! SUBMODULE - Ln:%d', line, line_no)
1422+
log.debug("%s !!! SUBMODULE - Ln:%d", line, line_no)
14251423

14261424
elif obj_type == "prog":
14271425
new_prog = fortran_program(file_ast, line_no, obj_info)
14281426
file_ast.add_scope(new_prog, FRegex.END_PROG)
1429-
log.debug('%s !!! PROGRAM - Ln:%d', line, line_no)
1427+
log.debug("%s !!! PROGRAM - Ln:%d", line, line_no)
14301428

14311429
elif obj_type == "sub":
14321430
keywords, _ = map_keywords(obj_info.keywords)
@@ -1439,7 +1437,7 @@ def parse(
14391437
keywords=keywords,
14401438
)
14411439
file_ast.add_scope(new_sub, FRegex.END_SUB)
1442-
log.debug('%s !!! SUBROUTINE - Ln:%d', line, line_no)
1440+
log.debug("%s !!! SUBROUTINE - Ln:%d", line, line_no)
14431441

14441442
elif obj_type == "fun":
14451443
keywords, _ = map_keywords(obj_info.keywords)
@@ -1467,7 +1465,7 @@ def parse(
14671465
keyword_info=keyword_info,
14681466
)
14691467
file_ast.add_variable(new_obj)
1470-
log.debug('%s !!! FUNCTION - Ln:%d', line, line_no)
1468+
log.debug("%s !!! FUNCTION - Ln:%d", line, line_no)
14711469

14721470
elif obj_type == "block":
14731471
name = obj_info
@@ -1476,7 +1474,7 @@ def parse(
14761474
name = f"#BLOCK{counters['block']}"
14771475
new_block = fortran_block(file_ast, line_no, name)
14781476
file_ast.add_scope(new_block, FRegex.END_BLOCK, req_container=True)
1479-
log.debug('%s !!! BLOCK - Ln:%d', line, line_no)
1477+
log.debug("%s !!! BLOCK - Ln:%d", line, line_no)
14801478

14811479
elif obj_type == "do":
14821480
counters["do"] += 1
@@ -1485,7 +1483,7 @@ def parse(
14851483
block_id_stack.append(obj_info)
14861484
new_do = fortran_do(file_ast, line_no, name)
14871485
file_ast.add_scope(new_do, FRegex.END_DO, req_container=True)
1488-
log.debug('%s !!! DO - Ln:%d', line, line_no)
1486+
log.debug("%s !!! DO - Ln:%d", line, line_no)
14891487

14901488
elif obj_type == "where":
14911489
# Add block if WHERE is not single line
@@ -1494,7 +1492,7 @@ def parse(
14941492
name = f"#WHERE{counters['do']}"
14951493
new_do = fortran_where(file_ast, line_no, name)
14961494
file_ast.add_scope(new_do, FRegex.END_WHERE, req_container=True)
1497-
log.debug('%s !!! WHERE - Ln:%d', line, line_no)
1495+
log.debug("%s !!! WHERE - Ln:%d", line, line_no)
14981496

14991497
elif obj_type == "assoc":
15001498
counters["block"] += 1
@@ -1514,14 +1512,14 @@ def parse(
15141512
)
15151513
except ValueError:
15161514
pass
1517-
log.debug('%s !!! ASSOCIATE - Ln:%d', line, line_no)
1515+
log.debug("%s !!! ASSOCIATE - Ln:%d", line, line_no)
15181516

15191517
elif obj_type == "if":
15201518
counters["if"] += 1
15211519
name = f"#IF{counters['if']}"
15221520
new_if = fortran_if(file_ast, line_no, name)
15231521
file_ast.add_scope(new_if, FRegex.END_IF, req_container=True)
1524-
log.debug('%s !!! IF - Ln:%d', line, line_no)
1522+
log.debug("%s !!! IF - Ln:%d", line, line_no)
15251523

15261524
elif obj_type == "select":
15271525
counters["select"] += 1
@@ -1536,22 +1534,22 @@ def parse(
15361534
)
15371535
if new_var is not None:
15381536
file_ast.add_variable(new_var)
1539-
log.debug('%s !!! SELECT - Ln:%d', line, line_no)
1537+
log.debug("%s !!! SELECT - Ln:%d", line, line_no)
15401538

15411539
elif obj_type == "typ":
15421540
keywords, _ = map_keywords(obj_info.keywords)
15431541
new_type = fortran_type(file_ast, line_no, obj_info.name, keywords)
15441542
if obj_info.parent is not None:
15451543
new_type.set_inherit(obj_info.parent)
15461544
file_ast.add_scope(new_type, FRegex.END_TYPED, req_container=True)
1547-
log.debug('%s !!! TYPE - Ln:%d', line, line_no)
1545+
log.debug("%s !!! TYPE - Ln:%d", line, line_no)
15481546

15491547
elif obj_type == "enum":
15501548
counters["block"] += 1
15511549
name = f"#ENUM{counters['block']}"
15521550
new_enum = fortran_enum(file_ast, line_no, name)
15531551
file_ast.add_scope(new_enum, FRegex.END_ENUMD, req_container=True)
1554-
log.debug('%s !!! ENUM - Ln:%d', line, line_no)
1552+
log.debug("%s !!! ENUM - Ln:%d", line, line_no)
15551553

15561554
elif obj_type == "int":
15571555
name = obj_info.name
@@ -1562,7 +1560,7 @@ def parse(
15621560
file_ast, line_no, name, abstract=obj_info.abstract
15631561
)
15641562
file_ast.add_scope(new_int, FRegex.END_INT, req_container=True)
1565-
log.debug('%s !!! INTERFACE - Ln:%d', line, line_no)
1563+
log.debug("%s !!! INTERFACE - Ln:%d", line, line_no)
15661564

15671565
elif obj_type == "gen":
15681566
new_int = fortran_int(
@@ -1573,19 +1571,19 @@ def parse(
15731571
for pro_link in obj_info.pro_links:
15741572
file_ast.add_int_member(pro_link)
15751573
file_ast.end_scope(line_no)
1576-
log.debug('%s !!! GENERIC - Ln:%d', line, line_no)
1574+
log.debug("%s !!! GENERIC - Ln:%d", line, line_no)
15771575

15781576
elif obj_type == "int_pro":
15791577
if file_ast.current_scope is not None:
15801578
if file_ast.current_scope.get_type() == INTERFACE_TYPE_ID:
15811579
for name in obj_info:
15821580
file_ast.add_int_member(name)
1583-
log.debug('%s !!! INTERFACE-PRO - Ln:%d', line, line_no)
1581+
log.debug("%s !!! INTERFACE-PRO - Ln:%d", line, line_no)
15841582

15851583
elif file_ast.current_scope.get_type() == SUBMODULE_TYPE_ID:
15861584
new_impl = fortran_scope(file_ast, line_no, obj_info[0])
15871585
file_ast.add_scope(new_impl, FRegex.END_PRO)
1588-
log.debug('%s !!! INTERFACE-IMPL - Ln:%d', line, line_no)
1586+
log.debug("%s !!! INTERFACE-IMPL - Ln:%d", line, line_no)
15891587

15901588
elif obj_type == "use":
15911589
file_ast.add_use(
@@ -1594,15 +1592,15 @@ def parse(
15941592
obj_info.only_list,
15951593
obj_info.rename_map,
15961594
)
1597-
log.debug('%s !!! USE - Ln:%d', line, line_no)
1595+
log.debug("%s !!! USE - Ln:%d", line, line_no)
15981596

15991597
elif obj_type == "import":
16001598
file_ast.add_use("#IMPORT", line_no, obj_info)
1601-
log.debug('%s !!! IMPORT - Ln:%d', line, line_no)
1599+
log.debug("%s !!! IMPORT - Ln:%d", line, line_no)
16021600

16031601
elif obj_type == "inc":
16041602
file_ast.add_include(obj_info, line_no)
1605-
log.debug('%s !!! INCLUDE - Ln:%d', line, line_no)
1603+
log.debug("%s !!! INCLUDE - Ln:%d", line, line_no)
16061604

16071605
elif obj_type == "vis":
16081606
if file_ast.current_scope is None:
@@ -1618,7 +1616,7 @@ def parse(
16181616
else:
16191617
for word in obj_info.obj_names:
16201618
file_ast.add_public(word)
1621-
log.debug('%s !!! VISIBILITY - Ln:%d', line, line_no)
1619+
log.debug("%s !!! VISIBILITY - Ln:%d", line, line_no)
16221620

16231621
file_ast.close_file(line_no)
16241622
if debug:
@@ -1698,7 +1696,7 @@ def parse_do_fixed_format(
16981696
file_ast.end_scope(ln)
16991697
block_id_stack.pop()
17001698
did_close = True
1701-
log.debug('%s !!! END DO-LABELLED - Ln:%d', line, ln)
1699+
log.debug("%s !!! END DO-LABELLED - Ln:%d", line, ln)
17021700
if did_close:
17031701
return True
17041702
return False
@@ -1716,10 +1714,26 @@ def _parse_implicit(self, line: str, ln: int, file_ast: fortran_ast):
17161714
else:
17171715
file_ast.current_scope.set_implicit(True, ln)
17181716

1719-
log.debug('%s !!! IMPLICIT - Ln:%d', line, ln)
1717+
log.debug("%s !!! IMPLICIT - Ln:%d", line, ln)
17201718
return True
17211719

1722-
def _parse_contains(self, line: str, ln: int, file_ast: fortran_ast):
1720+
def parse_contains(self, line: str, ln: int, file_ast: fortran_ast) -> bool:
1721+
"""Parse contain statements
1722+
1723+
Parameters
1724+
----------
1725+
line : str
1726+
Document line
1727+
ln : int
1728+
Line number
1729+
file_ast : fortran_ast
1730+
AST object
1731+
1732+
Returns
1733+
-------
1734+
bool
1735+
True if a contains is present, False otherwise
1736+
"""
17231737
match = FRegex.CONTAINS.match(line)
17241738
if match is None:
17251739
return False
@@ -1733,7 +1747,7 @@ def _parse_contains(self, line: str, ln: int, file_ast: fortran_ast):
17331747
msg = "Multiple CONTAINS statements in scope"
17341748
if msg:
17351749
file_ast.add_error(msg, Severity.error, ln, match.start(1), match.end(1))
1736-
log.debug('%s !!! CONTAINS - Ln:%d', line, ln)
1750+
log.debug("%s !!! CONTAINS - Ln:%d", line, ln)
17371751
return True
17381752

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

0 commit comments

Comments
 (0)