mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Updated the help messages for SyntaxErrors.
This commit is contained in:
parent
aea2f421e8
commit
b82991609e
@ -203,7 +203,11 @@ class Tokenizer:
|
|||||||
while True:
|
while True:
|
||||||
token = lexer.get_token()
|
token = lexer.get_token()
|
||||||
if not token:
|
if not token:
|
||||||
raise SyntaxError, 'Missing "%s".' % self.right
|
raise SyntaxError, 'Missing "%s". You may want to ' \
|
||||||
|
'quote your arguments with double ' \
|
||||||
|
'quotes in order to prevent extra ' \
|
||||||
|
'brackets from being evaluated ' \
|
||||||
|
'as nested commands.' % self.right
|
||||||
elif token == self.right:
|
elif token == self.right:
|
||||||
return ret
|
return ret
|
||||||
elif token == self.left:
|
elif token == self.left:
|
||||||
@ -226,47 +230,47 @@ class Tokenizer:
|
|||||||
break
|
break
|
||||||
elif token == '|' and conf.supybot.pipeSyntax():
|
elif token == '|' and conf.supybot.pipeSyntax():
|
||||||
if not args:
|
if not args:
|
||||||
raise SyntaxError, '"|" with nothing preceding.'
|
raise SyntaxError, '"|" with nothing preceding. I ' \
|
||||||
|
'obviously can\'t do a pipe with ' \
|
||||||
|
'nothing before the |.'
|
||||||
ends.append(args)
|
ends.append(args)
|
||||||
args = []
|
args = []
|
||||||
elif conf.supybot.bracketSyntax():
|
elif conf.supybot.bracketSyntax():
|
||||||
if token == self.left:
|
if token == self.left:
|
||||||
args.append(self._insideBrackets(lexer))
|
args.append(self._insideBrackets(lexer))
|
||||||
elif token == self.right:
|
elif token == self.right:
|
||||||
raise SyntaxError, 'Spurious "%s".' % self.right
|
raise SyntaxError, 'Spurious "%s". You may want to ' \
|
||||||
|
'quote your arguments with double ' \
|
||||||
|
'quotes in order to prevent extra ' \
|
||||||
|
'brackets from being evaluated ' \
|
||||||
|
'as nested commands.' % self.right
|
||||||
else:
|
else:
|
||||||
args.append(self._handleToken(token))
|
args.append(self._handleToken(token))
|
||||||
else:
|
else:
|
||||||
args.append(self._handleToken(token))
|
args.append(self._handleToken(token))
|
||||||
if ends:
|
if ends:
|
||||||
if not args:
|
if not args:
|
||||||
raise SyntaxError, '"|" with nothing following.'
|
raise SyntaxError, '"|" with nothing following. I ' \
|
||||||
|
'obviously can\'t do a pipe with ' \
|
||||||
|
'nothing before the |.'
|
||||||
args.append(ends.pop())
|
args.append(ends.pop())
|
||||||
while ends:
|
while ends:
|
||||||
args[-1].append(ends.pop())
|
args[-1].append(ends.pop())
|
||||||
return args
|
return args
|
||||||
|
|
||||||
_lastTokenized = None
|
|
||||||
_lastTokenizeResult = None
|
|
||||||
def tokenize(s):
|
def tokenize(s):
|
||||||
"""A utility function to create a Tokenizer and tokenize a string."""
|
"""A utility function to create a Tokenizer and tokenize a string."""
|
||||||
global _lastTokenized, _lastTokenizeResult
|
|
||||||
start = time.time()
|
start = time.time()
|
||||||
try:
|
try:
|
||||||
if s != _lastTokenized:
|
tokens = ''
|
||||||
_lastTokenized = s
|
if conf.supybot.bracketSyntax():
|
||||||
tokens = ''
|
tokens = conf.supybot.brackets()
|
||||||
if conf.supybot.bracketSyntax():
|
if conf.supybot.pipeSyntax():
|
||||||
tokens = conf.supybot.brackets()
|
tokens = '%s|' % tokens
|
||||||
if conf.supybot.pipeSyntax():
|
return Tokenizer(tokens).tokenize(s)
|
||||||
tokens = '%s|' % tokens
|
|
||||||
_lastTokenizeResult = Tokenizer(tokens).tokenize(s)
|
|
||||||
except ValueError, e:
|
except ValueError, e:
|
||||||
_lastTokenized = None
|
|
||||||
_lastTokenizedResult = None
|
|
||||||
raise SyntaxError, str(e)
|
raise SyntaxError, str(e)
|
||||||
#log.debug('tokenize took %s seconds.' % (time.time() - start))
|
#log.debug('tokenize took %s seconds.' % (time.time() - start))
|
||||||
return copy.deepcopy(_lastTokenizeResult)
|
|
||||||
|
|
||||||
def getCommands(tokens):
|
def getCommands(tokens):
|
||||||
"""Given tokens as output by tokenize, returns the command names."""
|
"""Given tokens as output by tokenize, returns the command names."""
|
||||||
|
Loading…
Reference in New Issue
Block a user