Fixed a nasty bug where pipe syntax would still work if it's disabled but

the pipe character is spaced out, as in: @foo | bar
Also added supybot.bracketSyntax; defaults to True, don't worry. ;)
This commit is contained in:
Stéphan Kochen 2004-02-18 15:39:30 +00:00
parent ffe0c5c5d9
commit f08f875d3c
2 changed files with 17 additions and 13 deletions

View File

@ -169,7 +169,7 @@ class Tokenizer:
# #
# These are the characters valid in a token. Everything printable except # These are the characters valid in a token. Everything printable except
# double-quote, left-bracket, and right-bracket. # 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 = '"' quotes = '"'
def __init__(self, tokens=''): def __init__(self, tokens=''):
# Add a '|' to tokens to have the pipe syntax. # Add a '|' to tokens to have the pipe syntax.
@ -207,15 +207,16 @@ class Tokenizer:
token = lexer.get_token() token = lexer.get_token()
if not token: if not token:
break break
elif token == '|': elif token == '|' and conf.supybot.pipeSyntax():
if not args: if not args:
raise SyntaxError, '"|" with nothing preceding' raise SyntaxError, '"|" with nothing preceding'
ends.append(args) ends.append(args)
args = [] args = []
elif token == '[': elif conf.supybot.bracketSyntax():
args.append(self._insideBrackets(lexer)) if token == '[':
elif token == ']': args.append(self._insideBrackets(lexer))
raise SyntaxError, 'Spurious "["' elif token == ']':
raise SyntaxError, 'Spurious "["'
else: else:
args.append(self._handleToken(token)) args.append(self._handleToken(token))
if ends: if ends:
@ -235,10 +236,11 @@ def tokenize(s):
try: try:
if s != _lastTokenized: if s != _lastTokenized:
_lastTokenized = s _lastTokenized = s
tokens = ''
if conf.supybot.bracketSyntax():
tokens = '[]'
if conf.supybot.pipeSyntax(): if conf.supybot.pipeSyntax():
tokens = '|' tokens = '%s|' % tokens
else:
tokens = ''
_lastTokenizeResult = Tokenizer(tokens).tokenize(s) _lastTokenizeResult = Tokenizer(tokens).tokenize(s)
except ValueError, e: except ValueError, e:
_lastTokenized = None _lastTokenized = None

View File

@ -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 messages. For safety purposes (so the bot can't possibly flood) it will
normally send everything in a single message.""")) 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 supybot.register('pipeSyntax', registry.Boolean(False, """Supybot allows
nested commands; generally, commands are nested via square brackets. Supybot nested commands. Enabling this option will allow nested commands with a syntax
can also provide a syntax more similar to UNIX pipes. The square bracket similar to UNIX pipes, for example: 'bot: foo | bar'."""))
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]'."""))
supybot.reply.register('whenNotCommand', registry.Boolean(True, """ supybot.reply.register('whenNotCommand', registry.Boolean(True, """
Determines whether the bot will reply with an error message when it is Determines whether the bot will reply with an error message when it is