mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-02-02 15:44:06 +01:00
Added supybot.brackets for specifying what valid bracket characters are.
This commit is contained in:
parent
d9c535f2bc
commit
71ea32c811
@ -1,3 +1,6 @@
|
|||||||
|
* Added supybot.brackets, a configuration variable for specifying
|
||||||
|
which set of matching brackets to use for nested commands. Valid
|
||||||
|
values are [] (the default), {}, <>, and ().
|
||||||
* Added a configuration variable to ChannelLogger, timestamp,
|
* Added a configuration variable to ChannelLogger, timestamp,
|
||||||
which determines whether the bot will timestamp its logfiles.
|
which determines whether the bot will timestamp its logfiles.
|
||||||
This is a channel-specific variable, of course.
|
This is a channel-specific variable, of course.
|
||||||
|
@ -175,6 +175,9 @@ class Tokenizer:
|
|||||||
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.
|
||||||
self.validChars = self.validChars.translate(string.ascii, tokens)
|
self.validChars = self.validChars.translate(string.ascii, tokens)
|
||||||
|
if len(tokens) >= 2:
|
||||||
|
self.left = tokens[0]
|
||||||
|
self.right = tokens[1]
|
||||||
|
|
||||||
def _handleToken(self, token):
|
def _handleToken(self, token):
|
||||||
if token[0] == token[-1] and token[0] in self.quotes:
|
if token[0] == token[-1] and token[0] in self.quotes:
|
||||||
@ -187,10 +190,10 @@ class Tokenizer:
|
|||||||
while True:
|
while True:
|
||||||
token = lexer.get_token()
|
token = lexer.get_token()
|
||||||
if not token:
|
if not token:
|
||||||
raise SyntaxError, 'Missing "]".'
|
raise SyntaxError, 'Missing "%s".' % self.right
|
||||||
elif token == ']':
|
elif token == self.right:
|
||||||
return ret
|
return ret
|
||||||
elif token == '[':
|
elif token == self.left:
|
||||||
ret.append(self._insideBrackets(lexer))
|
ret.append(self._insideBrackets(lexer))
|
||||||
else:
|
else:
|
||||||
ret.append(self._handleToken(token))
|
ret.append(self._handleToken(token))
|
||||||
@ -214,10 +217,10 @@ class Tokenizer:
|
|||||||
ends.append(args)
|
ends.append(args)
|
||||||
args = []
|
args = []
|
||||||
elif conf.supybot.bracketSyntax():
|
elif conf.supybot.bracketSyntax():
|
||||||
if token == '[':
|
if token == self.left:
|
||||||
args.append(self._insideBrackets(lexer))
|
args.append(self._insideBrackets(lexer))
|
||||||
elif token == ']':
|
elif token == self.right:
|
||||||
raise SyntaxError, 'Spurious "]".'
|
raise SyntaxError, 'Spurious "%s".' % self.right
|
||||||
else:
|
else:
|
||||||
args.append(self._handleToken(token))
|
args.append(self._handleToken(token))
|
||||||
else:
|
else:
|
||||||
@ -241,7 +244,7 @@ def tokenize(s):
|
|||||||
_lastTokenized = s
|
_lastTokenized = s
|
||||||
tokens = ''
|
tokens = ''
|
||||||
if conf.supybot.bracketSyntax():
|
if conf.supybot.bracketSyntax():
|
||||||
tokens = '[]'
|
tokens = conf.supybot.brackets()
|
||||||
if conf.supybot.pipeSyntax():
|
if conf.supybot.pipeSyntax():
|
||||||
tokens = '%s|' % tokens
|
tokens = '%s|' % tokens
|
||||||
_lastTokenizeResult = Tokenizer(tokens).tokenize(s)
|
_lastTokenizeResult = Tokenizer(tokens).tokenize(s)
|
||||||
|
@ -199,6 +199,15 @@ supybot.register('bracketSyntax', registry.Boolean(True, """Supybot allows
|
|||||||
nested commands. If this option is enabled users can nest commands using a
|
nested commands. If this option is enabled users can nest commands using a
|
||||||
bracket syntax, for example: 'bot: bar [foo]'."""))
|
bracket syntax, for example: 'bot: bar [foo]'."""))
|
||||||
|
|
||||||
|
class ValidBrackets(registry.OnlySomeStrings):
|
||||||
|
validStrings = ('[]', '<>', '{}', '()')
|
||||||
|
|
||||||
|
supybot.register('brackets', ValidBrackets('[]', """Supybot allows you to
|
||||||
|
specify what brackets are used for your nested commands. Valid sets of
|
||||||
|
brackets include [], <>, and {} (). [] has strong historical motivation, as
|
||||||
|
well as being the brackets that don't require shift. <> or () might be
|
||||||
|
slightly superior because they cannot occur in a nick."""))
|
||||||
|
|
||||||
supybot.register('pipeSyntax', registry.Boolean(False, """Supybot allows
|
supybot.register('pipeSyntax', registry.Boolean(False, """Supybot allows
|
||||||
nested commands. Enabling this option will allow nested commands with a syntax
|
nested commands. Enabling this option will allow nested commands with a syntax
|
||||||
similar to UNIX pipes, for example: 'bot: foo | bar'."""))
|
similar to UNIX pipes, for example: 'bot: foo | bar'."""))
|
||||||
|
@ -296,6 +296,16 @@ class String(Value):
|
|||||||
except ValueError: # This catches utils.safeEval(s) errors too.
|
except ValueError: # This catches utils.safeEval(s) errors too.
|
||||||
raise InvalidRegistryValue, '%r is not a string.' % s
|
raise InvalidRegistryValue, '%r is not a string.' % s
|
||||||
|
|
||||||
|
class OnlySomeStrings(String):
|
||||||
|
validStrings = ()
|
||||||
|
def setValue(self, s):
|
||||||
|
if s in self.validStrings:
|
||||||
|
String.setValue(self, s)
|
||||||
|
else:
|
||||||
|
raise InvalidRegistryValue, \
|
||||||
|
'%r is not a valid value. Valid values include %s.' % \
|
||||||
|
(utils.commaAndify(map(repr, self.validStrings)))
|
||||||
|
|
||||||
class NormalizedString(String):
|
class NormalizedString(String):
|
||||||
def set(self, s):
|
def set(self, s):
|
||||||
s = utils.normalizeWhitespace(s.strip())
|
s = utils.normalizeWhitespace(s.strip())
|
||||||
|
Loading…
Reference in New Issue
Block a user