"platforms/opencl/vscode:/vscode.git/clone" did not exist on "0f83a741a2dbd210e8eadeeb7d5fdd447c485ae7"
Commit 07426283 authored by Yutong Zhao's avatar Yutong Zhao
Browse files

Merge pull request #150 from rmcgibbo/gmxbug

Fix bug in gromacs top file parser
parents 167253d5 efd3fedd
......@@ -91,6 +91,9 @@ class GromacsTopFile(object):
# A preprocessor command.
fields = stripped.split()
command = fields[0]
if len(self._ifStack) != len(self._elseStack):
raise RuntimeError('#if/#else stack out of sync')
if command == '#include' and not ignore:
# Locate the file to include
name = stripped[len(command):].strip(' \t"<>')
......@@ -117,17 +120,29 @@ class GromacsTopFile(object):
raise ValueError('Illegal line in .top file: '+line)
name = fields[1]
self._ifStack.append(name in self._defines)
self._elseStack.append(False)
elif command == '#ifndef':
# See whether this block should be ignored.
if len(fields) < 2:
raise ValueError('Illegal line in .top file: '+line)
name = fields[1]
self._ifStack.append(name not in self._defines)
self._elseStack.append(False)
elif command == '#endif':
# Pop an entry off the if stack.
if len(self._ifStack) == 0:
raise ValueError('Unexpected line in .top file: '+line)
del(self._ifStack[-1])
del(self._elseStack[-1])
elif command == '#else':
# Reverse the last entry on the if stack
if len(self._ifStack) == 0:
raise ValueError('Unexpected line in .top file: '+line)
if self._elseStack[-1]:
raise ValueError('Unexpected line in .top file: '
'#else has already been used ' + line)
self._ifStack[-1] = (not self._ifStack[-1])
self._elseStack[-1] = True
elif not ignore:
# A line of data for the current category
......@@ -364,6 +379,7 @@ class GromacsTopFile(object):
self._currentCategory = None
self._ifStack = []
self._elseStack = []
self._moleculeTypes = {}
self._molecules = []
self._currentMoleculeType = None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment