Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
efd3fedd
Commit
efd3fedd
authored
Sep 26, 2013
by
Robert McGibbon
Browse files
Add an elseStack
parent
0e9144d4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
0 deletions
+13
-0
wrappers/python/simtk/openmm/app/gromacstopfile.py
wrappers/python/simtk/openmm/app/gromacstopfile.py
+13
-0
No files found.
wrappers/python/simtk/openmm/app/gromacstopfile.py
View file @
efd3fedd
...
@@ -90,6 +90,9 @@ class GromacsTopFile(object):
...
@@ -90,6 +90,9 @@ class GromacsTopFile(object):
# A preprocessor command.
# A preprocessor command.
fields
=
stripped
.
split
()
fields
=
stripped
.
split
()
command
=
fields
[
0
]
command
=
fields
[
0
]
if
len
(
self
.
_ifStack
)
!=
len
(
self
.
_elseStack
):
raise
RuntimeError
(
'#if/#else stack out of sync'
)
if
command
==
'#include'
and
not
ignore
:
if
command
==
'#include'
and
not
ignore
:
# Locate the file to include
# Locate the file to include
name
=
stripped
[
len
(
command
):].
strip
(
'
\t
"<>'
)
name
=
stripped
[
len
(
command
):].
strip
(
'
\t
"<>'
)
...
@@ -116,20 +119,29 @@ class GromacsTopFile(object):
...
@@ -116,20 +119,29 @@ class GromacsTopFile(object):
raise
ValueError
(
'Illegal line in .top file: '
+
line
)
raise
ValueError
(
'Illegal line in .top file: '
+
line
)
name
=
fields
[
1
]
name
=
fields
[
1
]
self
.
_ifStack
.
append
(
name
in
self
.
_defines
)
self
.
_ifStack
.
append
(
name
in
self
.
_defines
)
self
.
_elseStack
.
append
(
False
)
elif
command
==
'#ifndef'
:
elif
command
==
'#ifndef'
:
# See whether this block should be ignored.
# See whether this block should be ignored.
if
len
(
fields
)
<
2
:
if
len
(
fields
)
<
2
:
raise
ValueError
(
'Illegal line in .top file: '
+
line
)
raise
ValueError
(
'Illegal line in .top file: '
+
line
)
name
=
fields
[
1
]
name
=
fields
[
1
]
self
.
_ifStack
.
append
(
name
not
in
self
.
_defines
)
self
.
_ifStack
.
append
(
name
not
in
self
.
_defines
)
self
.
_elseStack
.
append
(
False
)
elif
command
==
'#endif'
:
elif
command
==
'#endif'
:
# Pop an entry off the if stack.
# Pop an entry off the if stack.
if
len
(
self
.
_ifStack
)
==
0
:
if
len
(
self
.
_ifStack
)
==
0
:
raise
ValueError
(
'Unexpected line in .top file: '
+
line
)
raise
ValueError
(
'Unexpected line in .top file: '
+
line
)
del
(
self
.
_ifStack
[
-
1
])
del
(
self
.
_ifStack
[
-
1
])
del
(
self
.
_elseStack
[
-
1
])
elif
command
==
'#else'
:
elif
command
==
'#else'
:
# Reverse the last entry on the if stack
# 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
.
_ifStack
[
-
1
]
=
(
not
self
.
_ifStack
[
-
1
])
self
.
_elseStack
[
-
1
]
=
True
elif
not
ignore
:
elif
not
ignore
:
# A line of data for the current category
# A line of data for the current category
...
@@ -362,6 +374,7 @@ class GromacsTopFile(object):
...
@@ -362,6 +374,7 @@ class GromacsTopFile(object):
self
.
_currentCategory
=
None
self
.
_currentCategory
=
None
self
.
_ifStack
=
[]
self
.
_ifStack
=
[]
self
.
_elseStack
=
[]
self
.
_moleculeTypes
=
{}
self
.
_moleculeTypes
=
{}
self
.
_molecules
=
[]
self
.
_molecules
=
[]
self
.
_currentMoleculeType
=
None
self
.
_currentMoleculeType
=
None
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment