diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2018-05-17 20:14:32 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-17 20:14:32 -0400 |
commit | c1fc040e9d86e3b6973f63ebaa43fdedc24d8815 (patch) | |
tree | 48cd39c6005b785bb167b97a4c6b12fef4891aaf /cmd2/parsing.py | |
parent | ff89bad1b0dd2a608081db5a8fa299ef43d66bc5 (diff) | |
parent | 8125d45412cce07b1316ef19fdcbc98deeb0a57a (diff) | |
download | cmd2-git-c1fc040e9d86e3b6973f63ebaa43fdedc24d8815.tar.gz |
Merge branch 'master' into pyscript
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r-- | cmd2/parsing.py | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index ce15bd38..655e0c58 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -250,23 +250,27 @@ class StatementParser: tokens = self.tokenize(rawinput) # of the valid terminators, find the first one to occur in the input - terminator_pos = len(tokens)+1 - for test_terminator in self.terminators: - try: - pos = tokens.index(test_terminator) - if pos < terminator_pos: + terminator_pos = len(tokens) + 1 + for pos, cur_token in enumerate(tokens): + for test_terminator in self.terminators: + if cur_token.startswith(test_terminator): terminator_pos = pos terminator = test_terminator + # break the inner loop, and we want to break the + # outer loop too break - except ValueError: - # the terminator is not in the tokens - pass + else: + # this else clause is only run if the inner loop + # didn't execute a break. If it didn't, then + # continue to the next iteration of the outer loop + continue + # inner loop was broken, break the outer + break if terminator: if terminator == LINE_FEED: terminator_pos = len(tokens)+1 - else: - terminator_pos = tokens.index(terminator) + # everything before the first terminator is the command and the args argv = tokens[:terminator_pos] (command, args) = self._command_and_args(argv) |