liblloyal 1.0.0
Composable primitives for llama.cpp inference
Loading...
Searching...
No Matches
lloyal::detail::SchemaConverter Class Reference

#include <json-schema-to-grammar.hpp>

Public Member Functions

 SchemaConverter (const std::function< json(const std::string &)> &fetch_json, bool dotall)
 
void resolve_refs (json &schema, const std::string &url)
 Resolve $ref pointers in JSON schema.
 
std::string _generate_constant_rule (const json &value)
 
std::string visit (const json &schema, const std::string &name)
 Convert schema node to GBNF rule.
 
void check_errors ()
 
std::string format_grammar ()
 

Friends

std::string lloyal::build_grammar (const std::function< void(const common_grammar_builder &)> &cb, const common_grammar_options &options)
 

Detailed Description

Definition at line 456 of file json-schema-to-grammar.hpp.

Constructor & Destructor Documentation

◆ SchemaConverter()

lloyal::detail::SchemaConverter::SchemaConverter ( const std::function< json(const std::string &)> &  fetch_json,
bool  dotall 
)
inline

Definition at line 484 of file json-schema-to-grammar.hpp.

Member Function Documentation

◆ _generate_constant_rule()

std::string lloyal::detail::SchemaConverter::_generate_constant_rule ( const json value)
inline

Definition at line 1028 of file json-schema-to-grammar.hpp.

◆ check_errors()

void lloyal::detail::SchemaConverter::check_errors ( )
inline

Definition at line 1240 of file json-schema-to-grammar.hpp.

◆ format_grammar()

std::string lloyal::detail::SchemaConverter::format_grammar ( )
inline

Definition at line 1251 of file json-schema-to-grammar.hpp.

◆ resolve_refs()

void lloyal::detail::SchemaConverter::resolve_refs ( json schema,
const std::string &  url 
)
inline

Resolve $ref pointers in JSON schema.

Recursively resolves all $ref fields in schema, fetching remote schemas as needed. Replaces relative refs (#/definitions/...) with absolute URLs and populates internal _refs map with resolved schema objects.

Parameters
schemaSchema object to resolve (modified in place)
urlBase URL for resolving relative references
Note
Handles both absolute (https://...) and relative (#/definitions/...) refs
Errors accumulated in _errors vector for batch reporting

Definition at line 964 of file json-schema-to-grammar.hpp.

◆ visit()

std::string lloyal::detail::SchemaConverter::visit ( const json schema,
const std::string &  name 
)
inline

Convert schema node to GBNF rule.

Main entry point for schema-to-grammar conversion. Dispatches to appropriate handler based on schema type (object, array, string, number, enum, etc.). Recursively processes nested schemas and generates corresponding GBNF rules.

Parameters
schemaSchema node to convert (JSON object, may contain type, properties, items, etc.)
nameRule name to generate (used as identifier in output grammar)
Returns
Generated GBNF rule definition
Note
Accumulates errors in _errors vector - call check_errors() after conversion
May throw std::runtime_error on unrecognized schema constructs
Warning
Complex method (~200+ lines) - handles all JSON Schema type keywords

Definition at line 1032 of file json-schema-to-grammar.hpp.

Friends And Related Symbol Documentation

◆ lloyal::build_grammar

std::string lloyal::build_grammar ( const std::function< void(const common_grammar_builder &)> &  cb,
const common_grammar_options options 
)
friend

The documentation for this class was generated from the following file: