Function parse_item

Source
pub fn parse_item(input: &str) -> IResult<&str, Item>
Expand description

Parse a complete inference item.

This is the main parsing function for inference items. It first attempts to parse as a task (looking for checkbox syntax), and falls back to parsing as a simple value if no checkbox is found.

§Grammar

item = task | value

§Examples

use aimx::{inference::{parse_item, Item}, writer::Prefix};

// Parse task with ordered prefix
assert_eq!(
    parse_item("1. [x] Completed task"),
    Ok(("Completed task", Item::Task(Prefix::Ordered, Some(true), "Completed task".to_string())))
);

// Parse task with unordered prefix
assert_eq!(
    parse_item("- [ ] Pending task"),
    Ok(("Pending task", Item::Task(Prefix::Unordered, None, "Pending task".to_string())))
);

// Parse value with ordered prefix
assert_eq!(
    parse_item("1. First item"),
    Ok(("First item", Item::Value(Prefix::Ordered, "First item".to_string())))
);

// Parse simple value without prefix
assert_eq!(
    parse_item("Simple value"),
    Ok(("Simple value", Item::Value(Prefix::None, "Simple value".to_string())))
);

§Arguments

  • input - The input string to parse

§Returns

Returns IResult containing remaining input and parsed Item