Function llg_new_matcher

pub unsafe extern "C" fn llg_new_matcher(
    init: &LlgConstraintInit,
    constraint_type: *const i8,
    data: *const i8,
) -> *mut LlgMatcher
Expand description

Create a new matcher from the given ConstraintInit Always returns a non-null value. Call llg_matcher_get_error() on the result to check for errors. init.ff_tokens_ok and init.backtrack_ok are ignored (backtracking is always disabled, and ff_tokens can be retrieved using llg_matcher_compute_ff_tokens()). The data is of different format, depending on constraint_type:

  • “regex” - data is regular expression in rust regex format see https://docs.rs/regex/latest/regex/#syntax
  • “json” or “json_schema” - data is (stringifed) JSON schema see https://github.com/guidance-ai/llguidance/blob/main/docs/json_schema.md
  • “json_object” - equivalent to JSON schema: {“type”:“object”}
  • “lark” - data is grammar in a variant of Lark syntax see https://github.com/guidance-ai/llguidance/blob/main/docs/syntax.md
  • “llguidance” or “guidance” - data is a list of Lark or JSON schemas in JSON format

§Safety

This function should only be called from C code.