Overview
So, Im in the middle of refactoring the project, and Im separating a bunch of parsing code. The code that concerns Im is pyparsing.
I have a very poor understanding of piparization, even spending a lot of time reading the official documentation. I am having problems because (1) pyparsing takes a (intentionally) unorthodox approach to parsing and (2) Im working on code that I did not write, with bad comments and an elementary set of existing grammars.
(I, too, cannot contact the original author.)
Failed test
Im using PyVows to check my code. One of my tests is the following (I think this is clear, even if you are not familiar with PyVows, let me know if this is not the case):
def test_multiline_command_ends(self, topic): output = parsed_input('multiline command ends\n\n',topic) expect(output).to_equal( r'''['multiline', 'command ends', '\n', '\n'] - args: command ends - multiline_command: multiline - statement: ['multiline', 'command ends', '\n', '\n'] - args: command ends - multiline_command: multiline - terminator: ['\n', '\n'] - terminator: ['\n', '\n']''')
But when I run the test, I get the following in the terminal:
Failed Test Results
Expected topic("['multiline', 'command ends']\n- args: command ends\n- command: multiline\n- statement: ['multiline', 'command ends']\n - args: command ends\n - command: multiline") to equal "['multiline', 'command ends', '\\n', '\\n']\n- args: command ends\n- multiline_command: multiline\n- statement: ['multiline', 'command ends', '\\n', '\\n']\n - args: command ends\n - multiline_command: multiline\n - terminator: ['\\n', '\\n']\n- terminator: ['\\n', '\\n']"
Note:
Since the output refers to the terminal, the expected output (second) has an additional backslash. This is normal. The test passed without problems before this piece of refactoring began.
Expected Behavior
The first line of output should match the second, but it is not. In particular, it does not include two newlines in this first list object.
So, I get this:
"['multiline', 'command ends']\n- args: command ends\n- command: multiline\n- statement: ['multiline', 'command ends']\n - args: command ends\n - command: multiline"
When should I get the following:
"['multiline', 'command ends', '\\n', '\\n']\n- args: command ends\n- multiline_command: multiline\n- statement: ['multiline', 'command ends', '\\n', '\\n']\n - args: command ends\n - multiline_command: multiline\n - terminator: ['\\n', '\\n']\n- terminator: ['\\n', '\\n']"
Earlier in the code there is also this statement:
pyparsing.ParserElement.setDefaultWhitespaceChars(' \t')
... Which, I think, should prevent just such an error. But I'm not sure.
Even if the problem cannot be identified with certainty, simply narrowing down where the problem is will be HUGE help.
Please let me know how I can take a step or two to fix this.
Edit: So, I have to publish the parser code for this, right? (Thanks for the tip, @andrew cooke!)
Parser Code
She has __init__
for my parser object.
I know his nightmare. That is why Im refactoring a project. ☺
def __init__(self, Cmd_object=None, *args, **kwargs):