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.

41 lines
1.2 KiB

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