Coverage for src/castep_linter/fortran/call_expression.py: 79%
24 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-23 18:07 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-11-23 18:07 +0000
1"""Module holding the CallExpression type"""
2from typing import ClassVar, List, Optional, Tuple
4from castep_linter.fortran.argument_parser import ArgParser, ArgType
5from castep_linter.fortran.fortran_node import Fortran, FortranNode
6from castep_linter.fortran.fortran_statement import FortranStatementParser
7from castep_linter.fortran.identifier import Identifier
10class CallExpression(FortranStatementParser):
11 """Class representing a fortran call expression"""
13 ALLOWED_NODES: ClassVar[List[Fortran]] = [Fortran.CALL_EXPRESSION, Fortran.SUBROUTINE_CALL]
15 def __init__(self, call_expression_node: FortranNode) -> None:
16 super().__init__(call_expression_node)
18 self.name = _get_name(call_expression_node)
20 try:
21 arg_list = call_expression_node.get(Fortran.ARGUMENT_LIST)
22 except KeyError:
23 arg_list = None
25 self.args = ArgParser(arg_list)
27 def get_arg(
28 self, keyword: Identifier, position: Optional[int] = None
29 ) -> Tuple[ArgType, FortranNode]:
30 """Get an argument from the call expression"""
31 return self.args.get(keyword, position)
33 def __str__(self):
34 return f"{self.name=} {self.args=}"
37def _get_name(node: FortranNode) -> Identifier:
38 try:
39 return Identifier.from_node(node.get(Fortran.IDENTIFIER))
40 except KeyError:
41 return Identifier("")