rpg-chat-command-parser

Crates.iorpg-chat-command-parser
lib.rsrpg-chat-command-parser
version0.1.0
sourcesrc
created_at2024-11-24 18:08:40.249615
updated_at2024-11-24 18:08:40.249615
descriptionA command line parser for RPG-like chat commands. Processes commands such as '/heal Player1', '/equip sword', or '/party invite Player2', validates their structure, and produces structured output for integration into games.
homepagehttps://github.com/Emril44/rpg-chat-command-parser
repositoryhttps://github.com/Emril44/rpg-chat-command-parser
max_upload_size
id1459483
size28,345
M. K. (Emril44)

documentation

README

rpg-chat-command-parser

rpg-chat-command-parser is a Rust library and CLI for parsing and validating RPG-style chat commands. It processes commands in the format commonly used in role-playing games, ensuring correct syntax and extracting useful data for integration into games or simulation systems.

Parsing Process

Supported Commands

The parser processes commands like:

  • /cast fireball --power=high
  • /equip sword
  • /heal Player1 --boost=strong

Grammar Overview

The grammar is defined using Pest and follows these rules:

  1. Command: Must start with /.
  2. Verb: Specifies the action (e.g., cast, equip).
  3. Target: Optional object of the action (e.g., fireball, sword).
  4. Flags: Optional key-value modifiers (e.g., --power=high).

Diagram of Grammar Rules

command:

command

command  ::= '/' 'alphanumeric word' 'space' target 'space' flag*

target:

target

target   ::= 'alphanumeric word'
           | quoted_string

referenced by:

  • command

flag:

flag

flag     ::= '--' 'alphanumeric word' '=' value?
           | bad_flag

referenced by:

  • command

value:

value

value    ::= 'alphanumeric word'
           | quoted_string

referenced by:

  • flag

quoted_string:

quoted_string

quoted_string
         ::= '"' 'text without double-quotes' '"'

referenced by:

  • target
  • value

bad_flag

Usage

Parsed commands produce a structured output:

{
  "verb": "cast",
  "target": "fireball",
  "flags": {
    "power": "high"
  }
}
Commit count: 16

cargo fmt