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.

61 lines
1.5 KiB

  1. class Symbol(object):
  2. is_term = NotImplemented
  3. def __init__(self, name):
  4. self.name = name
  5. def __eq__(self, other):
  6. assert isinstance(other, Symbol), other
  7. return self.is_term == other.is_term and self.name == other.name
  8. def __ne__(self, other):
  9. return not (self == other)
  10. def __hash__(self):
  11. return hash(self.name)
  12. def __repr__(self):
  13. return '%s(%r)' % (type(self).__name__, self.name)
  14. class Terminal(Symbol):
  15. is_term = True
  16. def __init__(self, name, filter_out=False):
  17. self.name = name
  18. self.filter_out = filter_out
  19. class NonTerminal(Symbol):
  20. is_term = False
  21. class Rule(object):
  22. """
  23. origin : a symbol
  24. expansion : a list of symbols
  25. """
  26. def __init__(self, origin, expansion, alias=None, options=None):
  27. self.origin = origin
  28. self.expansion = expansion
  29. self.alias = alias
  30. self.options = options
  31. def __str__(self):
  32. return '<%s : %s>' % (self.origin, ' '.join(map(str,self.expansion)))
  33. def __repr__(self):
  34. return 'Rule(%r, %r, %r, %r)' % (self.origin, self.expansion, self.alias, self.options)
  35. class RuleOptions:
  36. def __init__(self, keep_all_tokens=False, expand1=False, priority=None):
  37. self.keep_all_tokens = keep_all_tokens
  38. self.expand1 = expand1
  39. self.priority = priority
  40. def __repr__(self):
  41. return 'RuleOptions(%r, %r, %r)' % (
  42. self.keep_all_tokens,
  43. self.expand1,
  44. self.priority,
  45. )