Module literal

Source
Expand description

Literal value parsing and representation for the AIM expression grammar.

This module defines the Literal enum that represents literal values in expressions, including booleans, numbers, text, dates, and tasks. It provides parsing functions for literal values and comprehensive type conversion capabilities.

Literal values are the fundamental building blocks of AIM expressions. They represent concrete values that don’t require evaluation and serve as the basis for type promotion and conversion operations throughout the expression evaluation system.

§Literal Types

  • Empty - Represents an empty or null value
  • Bool - Boolean values (true or false)
  • Date - Date and time values using the jiff crate’s DateTime
  • Number - 64-bit floating point numbers
  • Task - Task primitives with optional status and text description
  • Text - UTF-8 string values

§Type Conversion Rules

AIMX uses intuitive type conversion rules that follow these principles:

  • Boolean conversion: Non-zero numbers, non-empty text, existing dates are true
  • Date conversion: Numbers as Unix timestamps, text as date strings
  • Number conversion: Boolean true=1/false=0, dates as timestamps, parsable text
  • Task conversion: Status from boolean/numbers, text from any convertible value
  • Text conversion: String representation of any value

§Examples

use aimx::literal::Literal;
use aimx::typedef::Typedef;

// Creating literals
let bool_literal = Literal::from_bool(true);
let number_literal = Literal::from_number(42.0);
let text_literal = Literal::from_text("hello".to_string());

// Type checking
assert!(bool_literal.is_bool());
assert!(number_literal.is_number());
assert!(text_literal.is_text());

// Type conversion
let number_as_text = number_literal.clone().as_text().unwrap();
assert!(number_as_text.is_text());
assert_eq!(number_as_text.to_string(), "42");

// Type matching
assert!(number_literal.is_type(&Typedef::Number));
assert!(number_literal.is_type(&Typedef::Any));

§Parsing

The module provides parsing functions for all literal types:

See also: parse_date, parse_number, parse_text in the crate::literals module

Enums§

Literal
Represents a literal value in the AIM expression grammar.

Functions§

parse_bool
Parse a boolean literal: true or false.
parse_literal
Parse a literal value from input text according to AIM grammar rules.
parse_task
Parse a task literal: [status] description.