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.

54 lines
1.7 KiB

  1. from copy import deepcopy
  2. from .utils import Serialize
  3. from .lexer import TerminalDef
  4. ###{standalone
  5. class LexerConf(Serialize):
  6. __serialize_fields__ = 'terminals', 'ignore', 'g_regex_flags', 'use_bytes', 'lexer_type'
  7. __serialize_namespace__ = TerminalDef,
  8. def __init__(self, terminals, re_module, ignore=(), postlex=None, callbacks=None, g_regex_flags=0, skip_validation=False, use_bytes=False):
  9. self.terminals = terminals
  10. self.terminals_by_name = {t.name: t for t in self.terminals}
  11. assert len(self.terminals) == len(self.terminals_by_name)
  12. self.ignore = ignore
  13. self.postlex = postlex
  14. self.callbacks = callbacks or {}
  15. self.g_regex_flags = g_regex_flags
  16. self.re_module = re_module
  17. self.skip_validation = skip_validation
  18. self.use_bytes = use_bytes
  19. self.lexer_type = None
  20. def _deserialize(self):
  21. self.terminals_by_name = {t.name: t for t in self.terminals}
  22. def __deepcopy__(self, memo=None):
  23. return type(self)(
  24. deepcopy(self.terminals, memo),
  25. self.re_module,
  26. deepcopy(self.ignore, memo),
  27. deepcopy(self.postlex, memo),
  28. deepcopy(self.callbacks, memo),
  29. deepcopy(self.g_regex_flags, memo),
  30. deepcopy(self.skip_validation, memo),
  31. deepcopy(self.use_bytes, memo),
  32. )
  33. class ParserConf(Serialize):
  34. __serialize_fields__ = 'rules', 'start', 'parser_type'
  35. def __init__(self, rules, callbacks, start):
  36. assert isinstance(start, list)
  37. self.rules = rules
  38. self.callbacks = callbacks
  39. self.start = start
  40. self.parser_type = None
  41. ###}