This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

28 line
732 B

  1. class GrammarError(Exception):
  2. pass
  3. class ParseError(Exception):
  4. pass
  5. class UnexpectedToken(ParseError):
  6. def __init__(self, token, expected, seq, index):
  7. self.token = token
  8. self.expected = expected
  9. self.line = getattr(token, 'line', '?')
  10. self.column = getattr(token, 'column', '?')
  11. context = ' '.join(['%r(%s)' % (t.value, t.type) for t in seq[index:index+5]])
  12. message = ("Unexpected token %r at line %s, column %s.\n"
  13. "Expected: %s\n"
  14. "Context: %s" % (token.value, self.line, self.column, expected, context))
  15. super(ParseError, self).__init__(message)
  16. def is_terminal(sym):
  17. return sym.isupper() or sym[0] == '$'