Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::GrammarRegistry Class Reference

Centralized grammar registry for named GBNF grammars. More...

#include <entropic/inference/grammar_registry.h>

Public Member Functions

size_t load_bundled (const std::filesystem::path &grammar_dir)
 Load all bundled grammars from a directory.
 
bool register_grammar (const std::string &key, const std::string &gbnf_content, const std::string &source="runtime")
 Register a grammar by key with GBNF content string.
 
bool register_from_file (const std::string &key, const std::filesystem::path &path)
 Register a grammar from a file path.
 
bool deregister (const std::string &key)
 Remove a grammar from the registry.
 
std::string get (const std::string &key) const
 Get GBNF content string for a grammar key.
 
bool has (const std::string &key) const
 Check if a grammar key exists in the registry.
 
GrammarEntry entry (const std::string &key) const
 Get full entry metadata for a grammar key.
 
std::vector< GrammarEntrylist () const
 List all registered grammar keys.
 
size_t size () const
 Number of registered grammars.
 
void clear ()
 Remove all registered grammars.
 

Static Public Member Functions

static std::string validate (const std::string &gbnf_content)
 Validate a GBNF grammar string.
 

Detailed Description

Centralized grammar registry for named GBNF grammars.

Single concrete class (no three-layer hierarchy — one implementation, like AdapterManager and HookRegistry).

Version
1.9.3

Definition at line 45 of file grammar_registry.h.

Member Function Documentation

◆ clear()

void entropic::GrammarRegistry::clear ( )

Remove all registered grammars.

Version
1.9.3

Definition at line 291 of file grammar_registry.cpp.

◆ deregister()

bool entropic::GrammarRegistry::deregister ( const std::string &  key)

Remove a grammar from the registry.

Parameters
keyGrammar name to remove.
Returns
true if removed. false if key not found.

Bundled grammars can be deregistered (allows overriding defaults).

Version
1.9.3
Parameters
keyGrammar name to remove.
Returns
true if removed. false if key not found.

Definition at line 173 of file grammar_registry.cpp.

◆ entry()

GrammarEntry entropic::GrammarRegistry::entry ( const std::string &  key) const

Get full entry metadata for a grammar key.

Parameters
keyGrammar name.
Returns
GrammarEntry, or entry with empty key if not found.
Version
1.9.3
Parameters
keyGrammar name.
Returns
GrammarEntry, or entry with empty key if not found.

Definition at line 219 of file grammar_registry.cpp.

◆ get()

std::string entropic::GrammarRegistry::get ( const std::string &  key) const

Get GBNF content string for a grammar key.

Parameters
keyGrammar name.
Returns
GBNF content string, or empty string if not found.

Returns content regardless of validation status.

Version
1.9.3
Parameters
keyGrammar name.
Returns
GBNF content string, or empty string if not found.

Definition at line 191 of file grammar_registry.cpp.

◆ has()

bool entropic::GrammarRegistry::has ( const std::string &  key) const

Check if a grammar key exists in the registry.

Parameters
keyGrammar name.
Returns
true if registered.
Version
1.9.3
Parameters
keyGrammar name.
Returns
true if registered.

Definition at line 207 of file grammar_registry.cpp.

◆ list()

std::vector< GrammarEntry > entropic::GrammarRegistry::list ( ) const

List all registered grammar keys.

Returns
Vector of GrammarEntry metadata (content omitted for efficiency).
Version
1.9.3
Returns
Vector of GrammarEntry metadata (content omitted).

Definition at line 234 of file grammar_registry.cpp.

◆ load_bundled()

size_t entropic::GrammarRegistry::load_bundled ( const std::filesystem::path &  grammar_dir)

Load all bundled grammars from a directory.

Load all bundled .gbnf grammars from a directory.

Parameters
grammar_dirPath to data/grammars/ directory.
Returns
Number of grammars loaded.

Scans for *.gbnf files. Each file's stem becomes the key (e.g., "compactor.gbnf" -> key "compactor"). Files are read, validated, and registered. Invalid files are logged as WARNING and still registered with error metadata.

Version
1.9.3

Definition at line 81 of file grammar_registry.cpp.

◆ register_from_file()

bool entropic::GrammarRegistry::register_from_file ( const std::string &  key,
const std::filesystem::path &  path 
)

Register a grammar from a file path.

Parameters
keyUnique grammar name (if empty, uses filename stem).
pathPath to .gbnf file.
Returns
true on success. false if file unreadable or key exists.
Version
1.9.3
Parameters
keyUnique grammar name (if empty, uses filename stem).
pathPath to .gbnf file.
Returns
true on success. false if file unreadable or key exists.

Definition at line 151 of file grammar_registry.cpp.

◆ register_grammar()

bool entropic::GrammarRegistry::register_grammar ( const std::string &  key,
const std::string &  gbnf_content,
const std::string &  source = "runtime" 
)

Register a grammar by key with GBNF content string.

Parameters
keyUnique grammar name.
gbnf_contentRaw GBNF grammar string.
sourceOrigin tag ("runtime", "dynamic", "file").
Returns
true on success. false if key already exists.

The grammar is validated on registration. If validation fails, the grammar is still registered but entry.validated is false and entry.error is set.

Version
1.9.3
Parameters
keyUnique grammar name.
gbnf_contentRaw GBNF grammar string.
sourceOrigin tag.
Returns
true on success. false if key already exists.

Definition at line 118 of file grammar_registry.cpp.

◆ size()

size_t entropic::GrammarRegistry::size ( ) const

Number of registered grammars.

Returns
Count of registered grammars.
Version
1.9.3
Returns
Count of registered grammars.

Definition at line 281 of file grammar_registry.cpp.

◆ validate()

std::string entropic::GrammarRegistry::validate ( const std::string &  gbnf_content)
static

Validate a GBNF grammar string.

Parameters
gbnf_contentRaw GBNF string to validate.
Returns
Empty string on success, error description on failure.

Parses the grammar using llama_sampler_init_grammar() with a throwaway sampler. Does not require a loaded model. This is a static utility — can be called without registering the grammar.

Version
1.9.3
Parameters
gbnf_contentRaw GBNF string to validate.
Returns
Empty string on success, error description on failure.

Definition at line 256 of file grammar_registry.cpp.


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