This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

43 rader
1.1 KiB

  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. try:
  12. context = ' '.join(['%r(%s)' % (t.value, t.type) for t in seq[index:index+5]])
  13. except AttributeError:
  14. context = seq[index:index+5]
  15. message = ("Unexpected token %r at line %s, column %s.\n"
  16. "Expected: %s\n"
  17. "Context: %s" % (token, self.line, self.column, expected, context))
  18. super(ParseError, self).__init__(message)
  19. def is_terminal(sym):
  20. return sym.isupper() or sym[0] == '$'
  21. class LexerConf:
  22. def __init__(self, tokens, ignore, postlex):
  23. self.tokens = tokens
  24. self.ignore = ignore
  25. self.postlex = postlex
  26. class ParserConf:
  27. def __init__(self, rules, callback, start):
  28. self.rules = rules
  29. self.callback = callback
  30. self.start = start