code: def visit(self, schema: Dict[str, Any], name: str) -> str:
      schema_type: Optional[str] = schema.get("type")  # type: ignore
      rule_name = name or "root"
  
      if "$defs" in schema:
          # add defs to self._defs for later inlining
          for def_name, def_schema in schema["$defs"].items():
              self._defs[def_name] = def_schema
  
      if "oneOf" in schema or "anyOf" in schema:
          rule = " | ".join(
              (
                  self.visit(
                      alt_schema, f'{name}{"-" if name else ""}{i}'
                  )
                  for i, alt_schema in enumerate(
                      schema.get("oneOf") or schema["anyOf"]
                  )
              )
          )
          return self._add_rule(rule_name, rule)
  
      elif "const" in schema:
          return self._add_rule(
              rule_name, self._format_literal(schema["const"])
          )
  
      elif "enum" in schema:
          rule = " | ".join(
              (self._format_literal(v) for v in schema["enum"])
          )
          return self._add_rule(rule_name, rule)
  
      elif schema_type == "object" and "properties" in schema:
          # TODO: `required` keyword
          prop_order = self._prop_order
          prop_pairs = sorted(
              schema["properties"].items(),
              # sort by position in prop_order (if specified) then by key
              key=lambda kv: (
                  prop_order.get(kv[0], len(prop_order)),
                  kv[0],
              ),
          )
  
          rule = '"{" space'
          for i, (prop_name, prop_schema) in enumerate(prop_pairs):
              prop_rule_name = self.visit(
                  prop_schema, f'{name}{"-" if name else ""}{prop_name}'
              )
              if i > 0:
                  rule += ' "," space'
              rule += rf' {self._format_literal(prop_name)} space ":" space {prop_rule_name}'
          rule += ' "}" space'
  
          return self._add_rule(rule_name, rule)
  
      elif schema_type == "array" and "items" in schema:
          # TODO `prefixItems` keyword
          item_rule_name = self.visit(
              schema["items"], f'{name}{"-" if name else ""}item'
          )
          rule = f'"[" space ({item_rule_name} ("," space {item_rule_name})*)? "]" space'
          return self._add_rule(rule_name, rule)
  
      elif "$ref" in schema:
          ref = schema["$ref"]
          assert ref.startswith(
              "#/$defs/"
          ), f"Unrecognized schema: {schema}"
          # inline $defs
          def_name = ref[len("#/$defs/") :]
          def_schema = self._defs[def_name]
          return self.visit(
              def_schema, f'{name}{"-" if name else ""}{def_name}'
          )
  
      else:
          assert (
              schema_type in PRIMITIVE_RULES
          ), f"Unrecognized schema: {schema}"
          return self._add_rule(
              "root" if rule_name == "root" else schema_type,
              PRIMITIVE_RULES[schema_type],
          )
  
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 4 for calling the SchemaConverter obj's underlying member method code with example usage: obj.visit(schema, name) and returns: self, self, self, self, self, self, self