class_docstr: Low-level strategy implementation wrapping a Lark grammar.
  
  See ``from_lark`` for details.
class_docstr_tok: ["Low-level","strategy","implementation","wrapping","a","Lark","grammar",".","See","``","from_lark","``","for","details","."]
code: def __init__(self, grammar, start, explicit):
      assert isinstance(grammar, lark.lark.Lark)
      if start is None:
          start = grammar.options.start
      if not isinstance(start, list):
          start = [start]
      self.grammar = grammar
  
      # This is a total hack, but working around the changes is a nicer user
      # experience than breaking for anyone who doesn't instantly update their
      # installation of Lark alongside Hypothesis.
      compile_args = signature(grammar.grammar.compile).parameters
      if "terminals_to_keep" in compile_args:
          terminals, rules, ignore_names = grammar.grammar.compile(
              start, ()
          )
      elif "start" in compile_args:  # pragma: no cover
          # Support lark <= 0.10.0, without the terminals_to_keep argument.
          terminals, rules, ignore_names = grammar.grammar.compile(
              start
          )
      else:  # pragma: no cover
          # This branch is to support lark <= 0.7.1, without the start argument.
          terminals, rules, ignore_names = grammar.grammar.compile()
  
      self.names_to_symbols = {}
  
      for r in rules:
          t = r.origin
          self.names_to_symbols[t.name] = t
  
      for t in terminals:
          self.names_to_symbols[t.name] = Terminal(t.name)
  
      self.start = st.sampled_from(
          [self.names_to_symbols[s] for s in start]
      )
  
      self.ignored_symbols = tuple(
          self.names_to_symbols[n] for n in ignore_names
      )
  
      self.terminal_strategies = {
          t.name: st.from_regex(t.pattern.to_regexp(), fullmatch=True)
          for t in terminals
      }
      unknown_explicit = set(explicit) - get_terminal_names(
          terminals, rules, ignore_names
      )
      if unknown_explicit:
          raise InvalidArgument(
              "The following arguments were passed as explicit_strategies, "
              "but there is no such terminal production in this grammar: "
              + repr(sorted(unknown_explicit))
          )
      self.terminal_strategies.update(explicit)
  
      nonterminals = {}
  
      for rule in rules:
          nonterminals.setdefault(rule.origin.name, []).append(
              tuple(rule.expansion)
          )
  
      for v in nonterminals.values():
          v.sort(key=len)
  
      self.nonterminal_strategies = {
          k: st.sampled_from(v) for k, v in nonterminals.items()
      }
  
      self.__rule_labels = {}
  
file_path: catboost/contrib/python/hypothesis/py3/hypothesis/extra/lark.py
imports: from inspect import signature
  from typing import Dict, Optional
  import lark
  from lark.grammar import NonTerminal, Terminal
  from hypothesis import strategies
  from hypothesis.errors import InvalidArgument
  from hypothesis.internal.conjecture.utils import calc_label_from_name
  from hypothesis.internal.validation import check_type
  from hypothesis.strategies._internal.utils import cacheable, defines_strategy
label_desc: Use image node_id 1 to create a new LarkStrategy object from inherited base classes: st with example: obj = LarkStrategy(grammar, start, explicit)