diff --git a/src/callbacks.py b/src/callbacks.py index 644182443..c0bec7e53 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -169,7 +169,7 @@ class Tokenizer: # # These are the characters valid in a token. Everything printable except # double-quote, left-bracket, and right-bracket. - validChars = string.ascii.translate(string.ascii, '\x00\r\n \t"[]') + validChars = string.ascii.translate(string.ascii, '\x00\r\n \t"') quotes = '"' def __init__(self, tokens=''): # Add a '|' to tokens to have the pipe syntax. @@ -207,15 +207,16 @@ class Tokenizer: token = lexer.get_token() if not token: break - elif token == '|': + elif token == '|' and conf.supybot.pipeSyntax(): if not args: raise SyntaxError, '"|" with nothing preceding' ends.append(args) args = [] - elif token == '[': - args.append(self._insideBrackets(lexer)) - elif token == ']': - raise SyntaxError, 'Spurious "["' + elif conf.supybot.bracketSyntax(): + if token == '[': + args.append(self._insideBrackets(lexer)) + elif token == ']': + raise SyntaxError, 'Spurious "["' else: args.append(self._handleToken(token)) if ends: @@ -235,10 +236,11 @@ def tokenize(s): try: if s != _lastTokenized: _lastTokenized = s + tokens = '' + if conf.supybot.bracketSyntax(): + tokens = '[]' if conf.supybot.pipeSyntax(): - tokens = '|' - else: - tokens = '' + tokens = '%s|' % tokens _lastTokenizeResult = Tokenizer(tokens).tokenize(s) except ValueError, e: _lastTokenized = None diff --git a/src/conf.py b/src/conf.py index 13823ec3e..b2eab36af 100644 --- a/src/conf.py +++ b/src/conf.py @@ -175,11 +175,13 @@ the bot will send multi-message replies in a single messsage or in multiple messages. For safety purposes (so the bot can't possibly flood) it will normally send everything in a single message.""")) +supybot.register('bracketSyntax', registry.Boolean(True, """Supybot allows +nested commands. If this option is enabled users can nest commands using a +bracket syntax, for example: 'bot: bar [foo]'.""")) + supybot.register('pipeSyntax', registry.Boolean(False, """Supybot allows -nested commands; generally, commands are nested via square brackets. Supybot -can also provide a syntax more similar to UNIX pipes. The square bracket -nesting syntax is always enabled, but when this value is True, users can also -nest commands by saying 'bot: foo | bar' instead of 'bot: bar [foo]'.""")) +nested commands. Enabling this option will allow nested commands with a syntax +similar to UNIX pipes, for example: 'bot: foo | bar'.""")) supybot.reply.register('whenNotCommand', registry.Boolean(True, """ Determines whether the bot will reply with an error message when it is