Module parser

Source
Expand description

§Command Parser

This module defines the core functionality for parsing RPG-style chat commands. It uses the Pest parser library for grammar-based parsing.

§Grammar

The grammar is defined in the grammar.pest file and supports the following:

  • Verbs: The primary action of the command (e.g., /cast, /attack).
  • Targets: Optional targets for the action (e.g., /cast fireball).
  • Flags: Key-value pairs for additional parameters (e.g., –power=high).

§Example

use rpg_chat_command_parser::parse_command;

let input = “/cast fireball –power=high”; let parsed = parse_command(input).unwrap(); assert_eq!(parsed.verb, “cast”); assert_eq!(parsed.target, Some(“fireball”.to_string())); assert_eq!(parsed.flags.get(“power”), Some(&“high”.to_string()));

Structs§

ParsedCommand
Represents a parsed command with its components.

Enums§

Rule

Functions§

parse_command
Parses an input string into a ParsedCommand.