Function parse_key

Source
pub fn parse_key(input: &str) -> IResult<&str, (String, Suffix)>
Expand description

Parse an inference key according to the AIM grammar.

This function parses inference keys and their suffix patterns, which indicate how the key’s value should be interpreted. The parser tries each suffix pattern in order of specificity (most specific first).

§Grammar Patterns

  1. key_colon_eol = UCID ‘:’ whitespace? EOL
  2. key_eol = UCID whitespace? EOL
  3. key_colon = UCID ‘:’

§Examples

use aimx::inference::key::{parse_key, Suffix};

// ColonEol pattern
assert_eq!( 
    parse_key("INSTRUCTIONS:\n"), 
    Ok(("", ("INSTRUCTIONS".to_string(), Suffix::ColonEol)))
);

// Eol pattern
assert_eq!(
    parse_key("SYSTEM\n"),
    Ok(("", ("SYSTEM".to_string(), Suffix::Eol)))
);

// Colon pattern
assert_eq!(
    parse_key("MODEL:"),
    Ok(("", ("MODEL".to_string(), Suffix::ColonEol)))
);

§Arguments

  • input - The input string to parse

§Returns

Returns an IResult containing the remaining input and a tuple of:

  • The parsed key as a String
  • The detected Suffix pattern