Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pushing working parser #1

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>mkmf2</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.python.pydev.PyDevBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.python.pydev.pythonNature</nature>
</natures>
</projectDescription>
5 changes: 5 additions & 0 deletions .pydevproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?eclipse-pydev version="1.0"?><pydev_project>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python interpreter</pydev_property>
</pydev_project>
56 changes: 46 additions & 10 deletions parse.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/python
import re
import re;

verbose = True
vv = False
Expand All @@ -13,25 +13,57 @@
print(fname, ":\n ",fcontens)
f.close()


""" Set up the regex to find use statements ^\s*use """
module_dependencies = []
findUse = re.compile('^\s*use', re.IGNORECASE)
findOnly = re.compile('only\s*:', re.IGNORECASE)
""" Parse each line of the file for the regex ^\s*use """
findUseAmp = re.compile('^\s*use&', re.IGNORECASE)
findUseAmpSpc = re.compile('^\s*use\s+&', re.IGNORECASE)


'''Parse each line of the file for the regex ^\s*use '''
if verbose or vv:
print('Parse each line of the file for the regex ^\s*use ')
for line in fcontents.splitlines():
if findUse.match(line):
for index, line in enumerate(fcontents.splitlines()):
if findUse.match(line):
if verbose or vv:
print(line)
""" Split the line on a , because of multiple module possibility on a line """
splitModLineCom = line.split(",")
splitModLineCom = line.split(",")
print(splitModLineCom)
for mods in splitModLineCom:
""" If the current string has USE in it, split on white space. The second member of this list is a module """
if findUse.match(mods):
if (findUseAmp.match(mods) or findUseAmpSpc.match(mods)):
if fcontents.splitlines()[index+1].split(",")[1]:
splitmodLineCom = fcontents.splitlines()[index+1]
print(splitmodLineCom)
for mods in splitModLineCom:
alreadyExists = False
for md in module_dependencies:
if md == mods[0]:
alreadyExists = True
if vv:
print(fname,": the module ",md," is listd more than once. only keeping one")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a typo in "listed"

break;
if not alreadyExists:
module_dependencies.append(mods[0])
else:
temp = 2
while not fcontents.splitlines()[index+temp][1]:
temp += 1
splitmodLineCom = fcontents.splitlines()[index+temp]
for mods in splitModLineCom:
alreadyExists = False
for md in module_dependencies:
if md == mods[0]:
alreadyExists = True
if vv:
print(fname,": the module ",md," is listd more than once. only keeping one")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diyorzakirov07 another "listed" typo

break;
if not alreadyExists:
module_dependencies.append(mods[0])
if findUse.match(mods) and len(splitModLineCom) > 1:
mod1 = mods.split()
alreadyExist = False
""" Get rid of dupicate mentions of a module """
for md in module_dependencies:
if md == mod1[1]:
alreadyExist = True
Expand All @@ -40,7 +72,11 @@
break
if not alreadyExist:
module_dependencies.append(mod1[1])






if verbose or vv:
print("The dependencies for ",fname," are ",module_dependencies)

63 changes: 63 additions & 0 deletions parseShort.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/python
import re;
import os;

fName = "diag_manager.F90"


##Parses Fortran file and returns module dependencies
#
#This function takes in a file to parse through.
#Using regex pattern matching a module list is populated, cleaned up, and returned without duplicates.
def getModules(fileName):
MODS = []

fileContents = open(fileName).read()

##Regex pattern to find matches in the file
#Checks for USE and possible & on the same or next line, until module name is found signified by the '?'
#Ignores cases and tries to match on all lines
patternMatch = re.compile('^ *USE[ &\n]+.*?[ &\n]*,', re.IGNORECASE | re.M)

##Finds all possible matches in the file
#Puts all possible matches in a list
matches = re.findall(patternMatch, fileContents)

##Grooms and populates return list of modules
#Removes spaces, characters from pattern matching, and checks for duplicates
for match in matches:
match = match.lower().strip()
badChars = ["use", "&", '\n', ' ', ',']
#clean up the matches
for char in badChars:
match = match.replace(char, '')
if not match in MODS:
MODS.append(match)


return MODS

##Creates a Makefile.am
#Creates a Makefile.am in the path provided, resolving all the dependencies
def writeModules(modules, path):

makefile = open('Makefile.am', 'w')

fileList = os.listdir(path)

fortranMatch = re.compile('[.F90&]')

makefile.write("noinst_LTLIBRARIES = " + path + ".la\n")

for file in fileList:
if fotranMatch.match(file):
makefile.write(file + "\\n")

for mod in modules:
makefile.write(mod + ".$(FC_MODEXT) : " + mod + ".$(OBJEXT)\n")


if __name__ == '__main__':
#testing diag_manager.F90
print(getModules(fName))