diff options
-rw-r--r-- | cmd2/parsing.py | 9 | ||||
-rw-r--r-- | tests/test_shlexparsing.py | 11 |
2 files changed, 8 insertions, 12 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 164c7735..79d57a32 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -22,7 +22,8 @@ class Statement(str): self.raw = str(object) self.command = None self.multilineCommand = None - self.args = None + # has to be an empty string for compatibility with standard library cmd + self.args = '' self.terminator = None self.suffix = None self.pipeTo = None @@ -58,7 +59,8 @@ class CommandParser(): else: return s pattern = re.compile( - r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', + #r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', + r'/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"', re.DOTALL | re.MULTILINE ) rawinput = re.sub(pattern, replacer, rawinput) @@ -146,6 +148,7 @@ class CommandParser(): multilineCommand = None result = Statement(args) + result.raw = rawinput result.command = command result.args = args result.terminator = terminator @@ -162,7 +165,7 @@ class CommandParser(): and the args as a string. """ command = None - args = None + args = '' if tokens: command = tokens[0] diff --git a/tests/test_shlexparsing.py b/tests/test_shlexparsing.py index 9142e178..fd010384 100644 --- a/tests/test_shlexparsing.py +++ b/tests/test_shlexparsing.py @@ -14,7 +14,6 @@ Notes: are with pyparsing. - valid comment styles: - C-style -> /* comment */ - - C++-style -> // comment - Python/Shell style -> # comment Functions in cmd2.py to be modified: @@ -43,8 +42,8 @@ def test_parse_empty_string(parser): assert not results.command @pytest.mark.parametrize('tokens,command,args', [ - ( [], None, None), - ( ['command'], 'command', None ), + ( [], None, ''), + ( ['command'], 'command', '' ), ( ['command', 'arg1', 'arg2'], 'command', 'arg1 arg2') ]) def test_command_and_args(parser, tokens, command, args): @@ -113,12 +112,6 @@ def test_parse_what_if_quoted_strings_seem_to_start_comments(parser): assert results.args == 'if "quoted strings /* seem to " start comments?' assert not results.pipeTo -def test_cpp_comment(parser): - results = parser.parseString('hi // this is | all a comment */') - assert results.command == 'hi' - assert not results.args - assert not results.pipeTo - def test_simple_piped(parser): results = parser.parseString('simple | piped') assert results.command == 'simple' |