diff --git a/mitmproxy/command.py b/mitmproxy/command.py index c0f739eba..3107e27dc 100644 --- a/mitmproxy/command.py +++ b/mitmproxy/command.py @@ -141,7 +141,7 @@ class CommandManager(mitmproxy.types._CommandBase): def add(self, path: str, func: typing.Callable): self.commands[path] = Command(self, path, func) - # Collecting one-word commands for lexer + # Collecting one-word command names for lexer if len(path.split(".")) == 1: self.oneword_commands.append(path) @@ -220,6 +220,8 @@ class CommandManager(mitmproxy.types._CommandBase): Execute a command string. May raise CommandError. """ lex = lexer.create_lexer(cmdstr, self.oneword_commands) + print(list(lex)) + lex.lexpos = 0 parser_return = self.command_parser.parse(lexer=lex) return parser_return diff --git a/mitmproxy/language/lexer.py b/mitmproxy/language/lexer.py index 170be33e0..55d8c660a 100644 --- a/mitmproxy/language/lexer.py +++ b/mitmproxy/language/lexer.py @@ -9,7 +9,6 @@ from mitmproxy import exceptions class CommandLanguageLexer: tokens = ( "WHITESPACE", - "ARRAY", "COMMAND", "PLAIN_STR", "QUOTED_STR" @@ -19,11 +18,6 @@ class CommandLanguageLexer: plain_str = fr"[^{special_symbols}\s]+" t_ignore_WHITESPACE = r"\s+" # We won't ignore it in the new language - t_ARRAY = r"\w+(\,\w+)+" - t_QUOTED_STR = r""" - \'+[^\']*\'+ | # Single-quoted string - \"+[^\"]*\"+ # Double-quoted string - """ def __init__(self, oneword_commands: typing.Sequence[str]): self.oneword_commands = dict.fromkeys(oneword_commands, "COMMAND") @@ -32,6 +26,14 @@ class CommandLanguageLexer: r"""\w+(\.\w+)+""" return t + def t_QUOTED_STR(self, t): + r""" + \'+[^\']*\'+ | # Single-quoted string + \"+[^\"]*\"+ # Double-quoted string + """ + t.value = t.value.strip("'\"") + return t + @lex.TOKEN(plain_str) def t_PLAIN_STR(self, t): t.type = self.oneword_commands.get(t.value, "PLAIN_STR") diff --git a/mitmproxy/language/parser.py b/mitmproxy/language/parser.py index 779bc0984..0e5d2f445 100644 --- a/mitmproxy/language/parser.py +++ b/mitmproxy/language/parser.py @@ -35,15 +35,10 @@ class CommandLanguageParser: def p_argument(self, p): """argument : PLAIN_STR - | quoted - | ARRAY + | QUOTED_STR | COMMAND""" p[0] = p[1] - def p_quoted(self, p): - """quoted : QUOTED_STR""" - p[0] = p[1][1:-1] # removing quotes - def p_empty(self, p): """empty :""" diff --git a/mitmproxy/tools/console/commander/commander.py b/mitmproxy/tools/console/commander/commander.py index df3eaa5a6..8d8831863 100644 --- a/mitmproxy/tools/console/commander/commander.py +++ b/mitmproxy/tools/console/commander/commander.py @@ -103,6 +103,7 @@ class CommandBuffer: else: ret.append(("text", "")) ret.append(("text", " ")) + self.right() if remhelp: ret.append(("text", " ")) for v in remhelp: