At work I have a programming language encoded in a database record. I'm trying to write a print function in python to display what the record contains.
This is the code I'm having trouble with:
# Un-indent the block if necessary.
if func_option[row.FRML_FUNC_OPTN] in ['Endif', 'Else']:
self.indent = self.indent - 1
# if this is a new line, indent it.
if len(self.formulatext) <> 0 and self.formulatext[len(self.formulatext) - 1] == '\n':
for i in range(1,self.indent):
rowtext = ' ' + rowtext
# increase indent for 'then', 'else'
if func_option[row.FRML_FUNC_OPTN] in ['Then', 'Else']:
self.indent = self.indent + 1
When row.FRML____FUNC____OPTN equals 'Else', I expect it to first un-indent, then indent again, so that the 'else' is printed at a lower level of indentation, then the rest of the code is within. Instead this is the type of indentation I get:
IfThen
IfThen
Else
EndifComment
IfThen
Endif
IfThen
Else
Endif
Else
Endif
As you can see the 'Else' is still indented higher than the If / Endif. Any idea why this could be happening?
I did try sprinkling the code with debug statements the result of which is:
row: Else
row.FRML_FUNC_OPTN is : Elsedecrementing indent
row.FRML_FUNC_OPTN is : Elseincrementing indent
which means that the indent altering if's are indeed being entered...