liblloyal 1.0.0
Composable primitives for llama.cpp inference
Loading...
Searching...
No Matches
json-schema-to-grammar.hpp File Reference
#include "common.hpp"
#include "helpers.hpp"
#include <lloyal/nlohmann/json.hpp>
#include <algorithm>
#include <functional>
#include <limits>
#include <map>
#include <regex>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

Go to the source code of this file.

Classes

struct  lloyal::common_grammar_builder
 
struct  lloyal::common_grammar_options
 
struct  lloyal::detail::BuiltinRule
 
class  lloyal::detail::SchemaConverter
 

Namespaces

namespace  lloyal
 JSON Schema to Grammar Converter (Header-Only)
 
namespace  lloyal::detail
 

Functions

std::string lloyal::json_schema_to_grammar (const json &schema, bool force_gbnf=false)
 Convert JSON schema to GBNF grammar.
 
std::string lloyal::build_grammar (const std::function< void(const common_grammar_builder &)> &cb, const common_grammar_options &options={})
 Build grammar from callback.
 
bool lloyal::detail::is_reserved_name (const std::string &name)
 Check if name conflicts with GBNF reserved keywords.
 
std::regex lloyal::detail::INVALID_RULE_CHARS_RE ("[^a-zA-Z0-9-]+")
 
std::regex lloyal::detail::GRAMMAR_LITERAL_ESCAPE_RE ("[\r\n\"]")
 
std::regex lloyal::detail::GRAMMAR_RANGE_LITERAL_ESCAPE_RE ("[\r\n\"\\]\\-\\\\]")
 
std::string lloyal::detail::build_repetition (const std::string &item_rule, int min_items, int max_items, const std::string &separator_rule="")
 
void lloyal::detail::_build_min_max_int (int min_value, int max_value, std::stringstream &out, int decimals_left=16, bool top_level=true)
 
std::string lloyal::detail::replacePattern (const std::string &input, const std::regex &regex, const std::function< std::string(const std::smatch &)> &replacement)
 
std::string lloyal::detail::format_literal (const std::string &literal)
 

Variables

constexpr const char * lloyal::detail::SPACE_RULE = "| \" \" | \"\\n\"{1,2} [ \\t]{0,20}"
 
const std::unordered_map< std::string, BuiltinRulelloyal::detail::PRIMITIVE_RULES
 Built-in grammar rules for JSON primitives.
 
const std::unordered_map< std::string, BuiltinRulelloyal::detail::STRING_FORMAT_RULES
 Grammar rules for string format validation.
 
const std::unordered_map< char, std::string > lloyal::detail::GRAMMAR_LITERAL_ESCAPES
 
const std::unordered_set< char > lloyal::detail::NON_LITERAL_SET
 
const std::unordered_set< char > lloyal::detail::ESCAPED_IN_REGEXPS_BUT_NOT_IN_LITERALS