|
58 | 58 |
|
59 | 59 | logger = logging.getLogger(__name__)
|
60 | 60 | fortran_invs = {}
|
| 61 | +backup_desc = {} |
61 | 62 |
|
62 | 63 | # Fortran parser and formatter
|
63 | 64 | # ----------------------------
|
@@ -342,6 +343,7 @@ def scan(self):
|
342 | 343 |
|
343 | 344 | # Get module description
|
344 | 345 | block['desc'],block['synopsis'] = self.get_comment(modsrc, aslist=True)
|
| 346 | + |
345 | 347 |
|
346 | 348 | # Scan types and routines
|
347 | 349 | for subblock in block['body']:
|
@@ -393,6 +395,11 @@ def scan_container(self, block, insrc=None):
|
393 | 395 |
|
394 | 396 | # Comment
|
395 | 397 | block['desc'],block['synopsis'] = self.get_comment(subsrc, aslist=True)
|
| 398 | + |
| 399 | + if block['name'] in backup_desc or block['desc'] == []: |
| 400 | + pass |
| 401 | + else: |
| 402 | + backup_desc[block['name']]=block['desc'] |
396 | 403 |
|
397 | 404 | # Scan comments to find descriptions
|
398 | 405 | if block['desc'] and block['block'] in [
|
@@ -1391,10 +1398,26 @@ def format_var(self, block, indent=0, bullet=False):
|
1391 | 1398 | typeshape += '\n\n'
|
1392 | 1399 | thedescription = block.get('desc', None)
|
1393 | 1400 | try:
|
1394 |
| - attrs = re.split(r"default=", options['attrs']) |
1395 |
| - attrs[0] = re.sub(r",\s*", ", ",':Attributes: ' + attrs[0].strip(',')) |
1396 |
| - if len(attrs) > 1: |
1397 |
| - attrs[1] = ':Default: ' + attrs[1].strip(',') |
| 1401 | + |
| 1402 | + attrstmp = re.split(r"default=", options['attrs']) |
| 1403 | + attrs = [] |
| 1404 | + |
| 1405 | + pattern = r'bind\(\s*(\w+)\s*,\s*name\s*=\s*"(\w+)"\s*\)' |
| 1406 | + match = re.search(pattern, attrstmp[0]) |
| 1407 | + if match: |
| 1408 | + full_match = match.group(0) # e.g., 'bind(x, name="y")' |
| 1409 | + bindlang = match.group(1) # e.g., 'x' |
| 1410 | + bindname = match.group(2) # e.g., 'y' |
| 1411 | + attrstmp[0] = attrstmp[0].replace(full_match, '') |
| 1412 | + |
| 1413 | + if attrstmp[0].strip(',') != '': |
| 1414 | + attrs.append(re.sub(r",\s*", ", ",':Attributes: ' + attrstmp[0].strip(','))) |
| 1415 | + |
| 1416 | + if match: |
| 1417 | + attrs.append(':Bindings: '+'Language = **'+bindlang+'**, Name = **'+bindname+'** ') |
| 1418 | + |
| 1419 | + if len(attrstmp) > 1: |
| 1420 | + attrs.append(':Default: ' + attrstmp[1].strip(',')) |
1398 | 1421 | except:
|
1399 | 1422 | attrs = ''
|
1400 | 1423 | #Search for patterns in the description of the type :something $varname:`something else`
|
@@ -1481,7 +1504,18 @@ def format_interface(self, block):
|
1481 | 1504 |
|
1482 | 1505 | def format_routine(self, block, indent=0):
|
1483 | 1506 | """Format the description of a function, a subroutine or a program"""
|
1484 |
| - # Declaration of a subroutine or function |
| 1507 | + |
| 1508 | + try: |
| 1509 | + listbinds=block['bindlang'] |
| 1510 | + attrs = self.format_lines([':Bindings: ']) |
| 1511 | + attrlist=[] |
| 1512 | + for i in range(len(listbinds)): |
| 1513 | + stringtoadd = 'Language = **'+block['bindlang'][i][0]+'**, Name = **'+block['bindlang'][i][1]+'** ' |
| 1514 | + attrlist.append(stringtoadd) |
| 1515 | + attrs = attrs + self.format_lines(attrlist, bullet = len(listbinds)>1, indent=indent+1) |
| 1516 | + except: |
| 1517 | + attrs = '' |
| 1518 | + |
1485 | 1519 | if isinstance(block, six.string_types):
|
1486 | 1520 | if block not in list(self.programs.keys()) + \
|
1487 | 1521 | list(self.routines.keys()):
|
@@ -1512,17 +1546,36 @@ def format_routine(self, block, indent=0):
|
1512 | 1546 |
|
1513 | 1547 | # Treat variables in comment (subroutines and functions only)
|
1514 | 1548 | comments = list(block['desc']) + ['']
|
| 1549 | + if comments == ['']: |
| 1550 | + try: |
| 1551 | + comments = list(backup_desc[block['name']]) + [''] |
| 1552 | + except: |
| 1553 | + pass |
| 1554 | + |
| 1555 | + comments.append(attrs) |
| 1556 | + |
1515 | 1557 | if blocktype == 'subroutine' or blocktype == 'function':
|
1516 | 1558 | found = []
|
1517 |
| - for iline in range(len(comments)): |
1518 |
| - if 'vardescmatch' in block: |
1519 |
| - m = block['vardescmatch'](comments[iline]) |
| 1559 | + iline = 0 |
| 1560 | + while iline < len(comments): |
| 1561 | + for key in block['vars']: |
| 1562 | + sreg = r'^\s*@param\w*\s+(?P<varname>%s)\s*[:\-–—]\s*(?P<vardesc>.+)' % key |
| 1563 | + theregex = re.compile(sreg).match |
| 1564 | + m = theregex(comments[iline]) |
1520 | 1565 | if m:
|
1521 |
| - varname = m.group('varname') |
1522 |
| - found.append(varname) |
| 1566 | + varname = key |
1523 | 1567 | if varname != '':
|
1524 |
| - comments[iline] = self.format_argfield( |
1525 |
| - block['vars'][varname], block=block) |
| 1568 | + block['vars'][varname]['desc'] += ' ' + m.group('vardesc') |
| 1569 | + comments.pop(iline) |
| 1570 | + iline = iline - 1 |
| 1571 | + iline = iline + 1 |
| 1572 | + |
| 1573 | + #comments.append( |
| 1574 | + # self.format_argfield( |
| 1575 | + # block['vars'][varname], |
| 1576 | + # block=block)) |
| 1577 | + #found.append(varname) |
| 1578 | + |
1526 | 1579 | for varname in block['args'] + block['sortvars']:
|
1527 | 1580 | if varname not in found:
|
1528 | 1581 | comments.append(
|
@@ -1584,7 +1637,7 @@ def format_routine(self, block, indent=0):
|
1584 | 1637 | # calls.append(callto)
|
1585 | 1638 | #calls = '\n' + self.format_lines(calls, indent=indent + 1)
|
1586 | 1639 | #return declaration + description + use + calls + '\n\n'
|
1587 |
| - return declaration + description + use + '\n\n' |
| 1640 | + return declaration + description + use + '\n\n' |
1588 | 1641 |
|
1589 | 1642 | format_function = format_routine
|
1590 | 1643 | format_subroutine = format_routine
|
|
0 commit comments