class_docstr: Keeps reference counts of all the arguments, so that they are not
  garbage collected by Python.
class_docstr_tok: ["Keeps","reference","counts","of","all","the","arguments",",","so","that","they","are","not","garbage","collected","by","Python","."]
docstr: Convert a GBNF grammar to a Llama grammar.
docstr_tok: ["Convert","a","GBNF","grammar","to","a","Llama","grammar","."]
code: def from_string(
      cls, grammar: str, verbose: bool = True
  ) -> "LlamaGrammar":
      """Convert a GBNF grammar to a Llama grammar."""
      parsed_grammar = parse(const_char_p(grammar))  # type: parse_state
      if parsed_grammar.rules.empty():
          raise ValueError(
              f"{cls.from_string.__name__}: error parsing grammar file: parsed_grammar.rules is empty"
          )
      if verbose:
          print(f"{cls.from_string.__name__} grammar:", file=sys.stderr)
          print_grammar(sys.stderr, parsed_grammar)
          print(file=sys.stderr)
      return cls(parsed_grammar)
  
imports: from pathlib import Path
  import sys
  from ctypes import *
  from enum import Enum
  from itertools import islice
  from typing import Any, Callable, Dict, Generic, List, Optional, OrderedDict, TextIO, Tuple, TypeVar, Union, overload
  import llama_cpp.llama_cpp
  import json
  import re
  from typing import List, Optional
label_desc: Use image node_id 3 for calling the LlamaGrammar obj's underlying member method code with example usage: obj.from_string(cls, grammar, verbose) and returns: cls