This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

60 行
1.8 KiB

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