summaryrefslogtreecommitdiff
path: root/cmd2/parsing.py
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-04-23 21:13:33 -0600
committerkotfu <kotfu@kotfu.net>2018-04-23 21:13:33 -0600
commit4411d8d68c57e8cfca323b80369a8d3c5f11c9d4 (patch)
treeb2294656bcd14c4a44b5bc272c5de31648aa56a6 /cmd2/parsing.py
parent7f7adaf2fa211e877987aef075affe2a7082dbc5 (diff)
downloadcmd2-git-4411d8d68c57e8cfca323b80369a8d3c5f11c9d4.tar.gz
Multiline support mostly done
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r--cmd2/parsing.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py
index f4f9a6a3..2c01fb70 100644
--- a/cmd2/parsing.py
+++ b/cmd2/parsing.py
@@ -7,6 +7,8 @@ import shlex
import cmd2
+BLANK_LINE = '\n\n'
+
class Statement(str):
"""String subclass with additional attributes to store the results of parsing.
@@ -85,13 +87,19 @@ class CommandParser():
line = line.replace(shortcut, expansion, 1)
break
+ # handle the special case/hardcoded terminator of a blank line
+ # we have to do this before we shlex on whitespace because it
+ # destroys all unquoted whitespace in the input
+ terminator = None
+ if line[-2:] == BLANK_LINE:
+ terminator = BLANK_LINE
+
s = shlex.shlex(line, posix=False)
s.whitespace_split = True
tokens = self.split_on_punctuation(list(s))
# of the valid terminators, find the first one to occur in the input
terminator_pos = len(tokens)+1
- terminator = None
for test_terminator in self.terminators:
try:
pos = tokens.index(test_terminator)
@@ -104,7 +112,10 @@ class CommandParser():
pass
if terminator:
- terminator_pos = tokens.index(terminator)
+ if terminator == BLANK_LINE:
+ terminator_pos = len(tokens)+1
+ else:
+ terminator_pos = tokens.index(terminator)
# everything before the first terminator is the command and the args
(command, args) = self._command_and_args(tokens[:terminator_pos])
#terminator = tokens[terminator_pos]