3 # WARNING! Do not edit! https://waf.io/book/index.html#_obtaining_the_waf_file
8 # Thomas Nagy 2016 (ita)
12 INC_REGEX = """(?:^|['">]\s*;)\s*(?:|#\s*)INCLUDE\s+(?:\w+_)?[<"'](.+?)(?=["'>])"""
13 USE_REGEX = """(?:^|;)\s*USE(?:\s+|(?:(?:\s*,\s*(?:NON_)?INTRINSIC)?\s*::))\s*(\w+)"""
14 MOD_REGEX = """(?:^|;)\s*MODULE(?!\s*PROCEDURE)(?:\s+|(?:(?:\s*,\s*(?:NON_)?INTRINSIC)?\s*::))\s*(\w+)"""
16 re_inc = re.compile(INC_REGEX, re.I)
17 re_use = re.compile(USE_REGEX, re.I)
18 re_mod = re.compile(MOD_REGEX, re.I)
20 class fortran_parser(object):
24 * the nodes corresponding to the module names to produce
25 * the nodes corresponding to the include files used
26 * the module names used by the fortran files
28 def __init__(self, incpaths):
30 """Files already parsed"""
33 """List of :py:class:`waflib.Node.Node` representing the dependencies to return"""
36 """List of module names to return"""
38 self.incpaths = incpaths
39 """List of :py:class:`waflib.Node.Node` representing the include paths"""
41 def find_deps(self, node):
43 Parses a Fortran file to obtain the dependencies used/provided
45 :param node: fortran file to read
46 :type node: :py:class:`waflib.Node.Node`
47 :return: lists representing the includes, the modules used, and the modules created by a fortran file
48 :rtype: tuple of list of strings
54 for line in txt.splitlines():
55 # line by line regexp search? optimize?
56 m = re_inc.search(line)
58 incs.append(m.group(1))
59 m = re_use.search(line)
61 uses.append(m.group(1))
62 m = re_mod.search(line)
64 mods.append(m.group(1))
65 return (incs, uses, mods)
67 def start(self, node):
69 Start parsing. Use the stack ``self.waiting`` to hold nodes to iterate on
71 :param node: fortran file
72 :type node: :py:class:`waflib.Node.Node`
76 nd = self.waiting.pop(0)
81 Processes a single file during dependency parsing. Extracts files used
82 modules used and modules provided.
84 incs, uses, mods = self.find_deps(node)
89 self.tryfind_header(x)
93 if not name in self.names:
94 self.names.append(name)
98 if not name in self.names:
99 self.names.append(name)
101 def tryfind_header(self, filename):
103 Adds an include file to the list of nodes to process
105 :param filename: file name
106 :type filename: string
109 for n in self.incpaths:
110 found = n.find_resource(filename)
112 self.nodes.append(found)
113 self.waiting.append(found)
116 if not filename in self.names:
117 self.names.append(filename)