This repo contains code to mirror other repos. It also contains the code that is getting mirrored.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

69 satır
2.2 KiB

  1. from types import ModuleType
  2. from copy import deepcopy
  3. from .utils import Serialize
  4. from .lexer import TerminalDef, Token
  5. ###{standalone
  6. from typing import Any, Callable, Collection, Dict, Optional, TYPE_CHECKING
  7. if TYPE_CHECKING:
  8. from .lark import PostLex
  9. _Callback = Callable[[Token], Token]
  10. class LexerConf(Serialize):
  11. __serialize_fields__ = 'terminals', 'ignore', 'g_regex_flags', 'use_bytes', 'lexer_type'
  12. __serialize_namespace__ = TerminalDef,
  13. terminals: Collection[TerminalDef]
  14. re_module: ModuleType
  15. ignore: Collection[str]
  16. postlex: 'Optional[PostLex]'
  17. callbacks: Dict[str, _Callback]
  18. g_regex_flags: int
  19. skip_validation: bool
  20. use_bytes: bool
  21. def __init__(self, terminals: Collection[TerminalDef], re_module: ModuleType, ignore: Collection[str]=(), postlex: 'Optional[PostLex]'=None, callbacks: Optional[Dict[str, _Callback]]=None, g_regex_flags: int=0, skip_validation: bool=False, use_bytes: bool=False):
  22. self.terminals = terminals
  23. self.terminals_by_name = {t.name: t for t in self.terminals}
  24. assert len(self.terminals) == len(self.terminals_by_name)
  25. self.ignore = ignore
  26. self.postlex = postlex
  27. self.callbacks = callbacks or {}
  28. self.g_regex_flags = g_regex_flags
  29. self.re_module = re_module
  30. self.skip_validation = skip_validation
  31. self.use_bytes = use_bytes
  32. self.lexer_type = None
  33. def _deserialize(self):
  34. self.terminals_by_name = {t.name: t for t in self.terminals}
  35. def __deepcopy__(self, memo=None):
  36. return type(self)(
  37. deepcopy(self.terminals, memo),
  38. self.re_module,
  39. deepcopy(self.ignore, memo),
  40. deepcopy(self.postlex, memo),
  41. deepcopy(self.callbacks, memo),
  42. deepcopy(self.g_regex_flags, memo),
  43. deepcopy(self.skip_validation, memo),
  44. deepcopy(self.use_bytes, memo),
  45. )
  46. class ParserConf(Serialize):
  47. __serialize_fields__ = 'rules', 'start', 'parser_type'
  48. def __init__(self, rules, callbacks, start):
  49. assert isinstance(start, list)
  50. self.rules = rules
  51. self.callbacks = callbacks
  52. self.start = start
  53. self.parser_type = None
  54. ###}