git @ Cat's Eye Technologies Tamsin / f41fe09
Checkpoint -- scanner.peek(1) is not what I meant... Chris Pressey 10 years ago
2 changed file(s) with 9 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
1717 | slough = "h" & ("o" | "p").
1818 | maidenhead = "h" & ("o" | "p").
1919 | reading = "h" ("o" | "p").
20 ? expected '.' at line 3, column 14 in `filename`
20 ? expected ''.'' but found '(' at line 3, column 16 in 'filename'
2121
2222 When a scanning error occurs in the input to a Tamsin program, the filename,
2323 line number, and column number are reported.
185185 """
186186 return self.state.report_buffer(position, length)
187187
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,
191192 self.state.line_number,
192193 self.state.column_number))
193194
244245 def expect(self, t):
245246 r = self.consume(t)
246247 if r is None:
247 self.error("'%s'" % t)
248 self.error("'%s'" % t, self.scan())
248249 return r
249250
250251 def dump(self, indent=1):
302303 u'“'.encode('UTF-8'), u'”'.encode('UTF-8')
303304 )
304305 else:
305 scanner.error('identifiable character')
306 scanner.error('identifiable character', scanner.peek(1))
306307
307308 if scanner.startswith(('=', '(', ')', '[', ']', '{', '}', '!', ':', '/',
308309 '|', '&', ',', '.', '@', '+', '$',
321322 token += scanner.chop(1)
322323 return token
323324
324 scanner.error('identifiable character')
325 scanner.error('identifiable character', scanner.peek(1))
325326
326327 def consume_quoted(self, scanner, quote, close_quote):
327328 # assumes the start quote has already been chopped
336337 elif char == 'x':
337338 char = chr(int(scanner.chop(2), 16))
338339 else:
339 scanner.error('legal escape sequence')
340 scanner.error('legal escape sequence', '\\' + char)
340341 token += char
341342 scanner.chop(len(close_quote)) # chop ending quote
342343 # we add the specific close quote we expect, in case it was EOF