Function parse_task

Source
pub fn parse_task(input: &str) -> IResult<&str, (Option<bool>, String)>
Expand description

Parse a task literal: [status] description.

Task literals have a specific syntax that includes an optional status indicator followed by a text description. The status can be:

  • + or omitted: Represents a completed task (Some(true))
  • -: Represents a failed task (Some(false))
  • Empty space : Represents a pending task (None)

§Syntax

[status] description

Where status is optional and can be:

  • + for completed (positive)
  • - for failed (negative)
  • (space) or omitted for pending

§Arguments

  • input - A string slice containing the task literal to parse

§Returns

  • IResult<&str, (Option<bool>, String)> - A nom parser result containing:
    • Remaining input after parsing the task
    • Tuple with optional status (Some(bool)) and description text

§Examples

use aimx::parse_task;

// Completed task
let (remaining, (status, text)) = parse_task("[+] 'Complete assignment'").unwrap();
assert_eq!(remaining, "");
assert_eq!(status, Some(true));
assert_eq!(text, "Complete assignment");

// Failed task
let (remaining, (status, text)) = parse_task("[-] 'Failed attempt'").unwrap();
assert_eq!(remaining, "");
assert_eq!(status, Some(false));
assert_eq!(text, "Failed attempt");

// Pending task
let (remaining, (status, text)) = parse_task("[ ] 'Pending review'").unwrap();
assert_eq!(remaining, "");
assert_eq!(status, None);
assert_eq!(text, "Pending review");

§Error Handling

Returns a nom error if the input does not follow the task literal syntax:

  • Missing opening bracket [
  • Missing closing bracket ]
  • Invalid status character (only +, -, or space allowed)

§See Also