@@ -1658,36 +1658,59 @@ def parse(
1658
1658
log .debug (f"{ error ['range' ]} : { error ['message' ]} " )
1659
1659
return file_ast
1660
1660
1661
- def parse_imp_dim (self , name : str ):
1661
+ def parse_imp_dim (self , line : str ):
1662
+ """Parse the implicit dimension of an array e.g.
1663
+ var(3,4), var_name(size(val,1)*10)
1664
+
1665
+ Parameters
1666
+ ----------
1667
+ line : str
1668
+ line containing variable name
1669
+
1670
+ Returns
1671
+ -------
1672
+ tuple[str, str]
1673
+ truncated line, dimension string
1674
+ """
1662
1675
regex = re .compile (r"[ ]*\w+[ ]*(\()" , re .I )
1663
1676
# TODO: replace space
1664
- m = regex .match (name )
1677
+ m = regex .match (line )
1665
1678
if not m :
1666
- return name , None
1667
- i = find_paren_match (name [m .end (1 ) :])
1679
+ return line , None
1680
+ i = find_paren_match (line [m .end (1 ) :])
1668
1681
if i < 0 :
1669
- return name , None # triggers for autocomplete
1670
- dims = name [m .start (1 ) : m .end (1 ) + i + 1 ]
1671
- name = name [: m .start (1 )] + name [m .end (1 ) + i + 1 :]
1672
- return name , f"dimension{ dims } "
1682
+ return line , None # triggers for autocomplete
1683
+ dims = line [m .start (1 ) : m .end (1 ) + i + 1 ]
1684
+ line = line [: m .start (1 )] + line [m .end (1 ) + i + 1 :]
1685
+ return line , f"dimension{ dims } "
1686
+
1687
+ def parse_imp_char (self , line : str ):
1688
+ """Parse the implicit character length from a variable e.g.
1689
+ var_name*10 or var_name*(10), var_name*(size(val, 1))
1673
1690
1674
- def parse_imp_char (self , name : str ):
1691
+ Parameters
1692
+ ----------
1693
+ line : str
1694
+ line containing potential variable
1695
+
1696
+ Returns
1697
+ -------
1698
+ tuple[str, str]
1699
+ truncated line, character length
1700
+ """
1675
1701
implicit_len = re .compile (r"(\w+)[ ]*\*[ ]*(\d+|\()" , re .I )
1676
1702
# TODO: replace space in name
1677
- match = re .match (implicit_len , name )
1703
+ match = implicit_len .match (line )
1678
1704
if not match :
1679
- return name , None
1705
+ return line , None
1680
1706
if match .group (2 ) == "(" :
1681
- i = find_paren_match (name [match .end (2 ) :])
1707
+ i = find_paren_match (line [match .end (2 ) :])
1682
1708
if i < 0 :
1683
- return name , None # triggers for autocomplete
1684
- char_len = name [match .start (2 ) : match .end (2 ) + i + 1 ]
1709
+ return line , None # triggers for autocomplete
1710
+ char_len = line [match .start (2 ) : match .end (2 ) + i + 1 ]
1685
1711
elif match .group (2 ).isdigit ():
1686
1712
char_len = match .group (2 )
1687
- else :
1688
- raise ValueError ("No matching group(2) for implicit length" )
1689
- name = match .group (1 )
1690
- return name , f"*{ char_len } "
1713
+ return match .group (1 ), f"*{ char_len } "
1691
1714
1692
1715
def parse_end_scope_word (
1693
1716
self , line : str , ln : int , file_ast : FortranAST , match : re .Match
0 commit comments