|
Entropic 2.3.8
Local-first agentic inference engine
|
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< GrammarEntry > | list () 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. | |
Centralized grammar registry for named GBNF grammars.
Single concrete class (no three-layer hierarchy — one implementation, like AdapterManager and HookRegistry).
Definition at line 45 of file grammar_registry.h.
| void entropic::GrammarRegistry::clear | ( | ) |
| bool entropic::GrammarRegistry::deregister | ( | const std::string & | key | ) |
Remove a grammar from the registry.
| key | Grammar name to remove. |
Bundled grammars can be deregistered (allows overriding defaults).
| key | Grammar name to remove. |
Definition at line 173 of file grammar_registry.cpp.
| GrammarEntry entropic::GrammarRegistry::entry | ( | const std::string & | key | ) | const |
Get full entry metadata for a grammar key.
| key | Grammar name. |
| key | Grammar name. |
Definition at line 219 of file grammar_registry.cpp.
| std::string entropic::GrammarRegistry::get | ( | const std::string & | key | ) | const |
Get GBNF content string for a grammar key.
| key | Grammar name. |
Returns content regardless of validation status.
| key | Grammar name. |
Definition at line 191 of file grammar_registry.cpp.
| bool entropic::GrammarRegistry::has | ( | const std::string & | key | ) | const |
Check if a grammar key exists in the registry.
| key | Grammar name. |
| key | Grammar name. |
Definition at line 207 of file grammar_registry.cpp.
| std::vector< GrammarEntry > entropic::GrammarRegistry::list | ( | ) | const |
List all registered grammar keys.
Definition at line 234 of file grammar_registry.cpp.
| 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.
| grammar_dir | Path to data/grammars/ directory. |
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.
Definition at line 81 of file grammar_registry.cpp.
| bool entropic::GrammarRegistry::register_from_file | ( | const std::string & | key, |
| const std::filesystem::path & | path | ||
| ) |
Register a grammar from a file path.
| key | Unique grammar name (if empty, uses filename stem). |
| path | Path to .gbnf file. |
| key | Unique grammar name (if empty, uses filename stem). |
| path | Path to .gbnf file. |
Definition at line 151 of file grammar_registry.cpp.
| 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.
| key | Unique grammar name. |
| gbnf_content | Raw GBNF grammar string. |
| source | Origin tag ("runtime", "dynamic", "file"). |
The grammar is validated on registration. If validation fails, the grammar is still registered but entry.validated is false and entry.error is set.
| key | Unique grammar name. |
| gbnf_content | Raw GBNF grammar string. |
| source | Origin tag. |
Definition at line 118 of file grammar_registry.cpp.
| size_t entropic::GrammarRegistry::size | ( | ) | const |
Number of registered grammars.
Definition at line 281 of file grammar_registry.cpp.
|
static |
Validate a GBNF grammar string.
| gbnf_content | Raw GBNF string to validate. |
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.
| gbnf_content | Raw GBNF string to validate. |
Definition at line 256 of file grammar_registry.cpp.