185 | 185 |
"""
|
186 | 186 |
return self.state.report_buffer(position, length)
|
187 | 187 |
|
188 | |
def error(self, expected):
|
189 | |
raise ValueError(u"expected %s at line %s, column %s in `filename`" %
|
190 | |
(expected,
|
|
188 |
def error(self, expected, found):
|
|
189 |
raise ValueError(u"expected '%s' but found '%s' at "
|
|
190 |
"line %s, column %s in 'filename'" %
|
|
191 |
(expected, found,
|
191 | 192 |
self.state.line_number,
|
192 | 193 |
self.state.column_number))
|
193 | 194 |
|
|
244 | 245 |
def expect(self, t):
|
245 | 246 |
r = self.consume(t)
|
246 | 247 |
if r is None:
|
247 | |
self.error("'%s'" % t)
|
|
248 |
self.error("'%s'" % t, self.scan())
|
248 | 249 |
return r
|
249 | 250 |
|
250 | 251 |
def dump(self, indent=1):
|
|
302 | 303 |
u'“'.encode('UTF-8'), u'”'.encode('UTF-8')
|
303 | 304 |
)
|
304 | 305 |
else:
|
305 | |
scanner.error('identifiable character')
|
|
306 |
scanner.error('identifiable character', scanner.peek(1))
|
306 | 307 |
|
307 | 308 |
if scanner.startswith(('=', '(', ')', '[', ']', '{', '}', '!', ':', '/',
|
308 | 309 |
'|', '&', ',', '.', '@', '+', '$',
|
|
321 | 322 |
token += scanner.chop(1)
|
322 | 323 |
return token
|
323 | 324 |
|
324 | |
scanner.error('identifiable character')
|
|
325 |
scanner.error('identifiable character', scanner.peek(1))
|
325 | 326 |
|
326 | 327 |
def consume_quoted(self, scanner, quote, close_quote):
|
327 | 328 |
# assumes the start quote has already been chopped
|
|
336 | 337 |
elif char == 'x':
|
337 | 338 |
char = chr(int(scanner.chop(2), 16))
|
338 | 339 |
else:
|
339 | |
scanner.error('legal escape sequence')
|
|
340 |
scanner.error('legal escape sequence', '\\' + char)
|
340 | 341 |
token += char
|
341 | 342 |
scanner.chop(len(close_quote)) # chop ending quote
|
342 | 343 |
# we add the specific close quote we expect, in case it was EOF
|