MCPcopy Create free account
hub / github.com/ccxt/ccxt / __init__

Method __init__

python/ccxt/static_dependencies/lark/lark.py:267–452  ·  view source on GitHub ↗
(self, grammar: 'Union[Grammar, str, IO[str]]', **options)

Source from the content-addressed store, hash-verified

265 terminals: Collection[TerminalDef]
266
267 def __init__(self, grammar: 'Union[Grammar, str, IO[str]]', **options) -> None:
268 self.options = LarkOptions(options)
269 re_module: types.ModuleType
270
271 # Set regex or re module
272 use_regex = self.options.regex
273 if use_regex:
274 if _has_regex:
275 re_module = regex
276 else:
277 raise ImportError('`regex` module must be installed if calling `Lark(regex=True)`.')
278 else:
279 re_module = re
280
281 # Some, but not all file-like objects have a 'name' attribute
282 if self.options.source_path is None:
283 try:
284 self.source_path = grammar.name # type: ignore[union-attr]
285 except AttributeError:
286 self.source_path = '<string>'
287 else:
288 self.source_path = self.options.source_path
289
290 # Drain file-like objects to get their contents
291 try:
292 read = grammar.read # type: ignore[union-attr]
293 except AttributeError:
294 pass
295 else:
296 grammar = read()
297
298 cache_fn = None
299 cache_sha256 = None
300 if isinstance(grammar, str):
301 self.source_grammar = grammar
302 if self.options.use_bytes:
303 if not grammar.isascii():
304 raise ConfigurationError("Grammar must be ascii only, when use_bytes=True")
305
306 if self.options.cache:
307 if self.options.parser != 'lalr':
308 raise ConfigurationError("cache only works with parser='lalr' for now")
309
310 unhashable = ('transformer', 'postlex', 'lexer_callbacks', 'edit_terminals', '_plugins')
311 options_str = ''.join(k+str(v) for k, v in options.items() if k not in unhashable)
312 from . import __version__
313 s = grammar + options_str + __version__ + str(sys.version_info[:2])
314 cache_sha256 = sha256_digest(s)
315
316 if isinstance(self.options.cache, str):
317 cache_fn = self.options.cache
318 else:
319 if self.options.cache is not True:
320 raise ConfigurationError("cache argument must be bool or str")
321
322 try:
323 username = getpass.getuser()
324 except Exception:

Callers

nothing calls this directly

Calls 15

_loadMethod · 0.95
_build_parserMethod · 0.95
_build_lexerMethod · 0.95
saveMethod · 0.95
sha256_digestFunction · 0.90
verify_used_filesFunction · 0.90
load_grammarFunction · 0.90
LarkOptionsClass · 0.85
assert_configFunction · 0.85
LexerConfClass · 0.85
writeMethod · 0.80
ConfigurationErrorClass · 0.70

Tested by

no test coverage detected