Crates.io | board_game_parser |
lib.rs | board_game_parser |
version | 0.1.0 |
source | src |
created_at | 2024-11-21 07:45:23.132888 |
updated_at | 2024-11-21 07:45:23.132888 |
description | A Rust-based parser for board game data, designed for efficient data extraction and transformation. |
homepage | |
repository | |
max_upload_size | |
id | 1455832 |
size | 26,067 |
The Board Game Parser is a Rust-based utility designed to parse structured information about board games and convert it into a serialized JSON format. This tool processes text files containing data about board games and extracts details such as the game's name, author, age suitability, playtime, player count, and price.
The parser expects an input file with the following structure:
Name: <game name>
Author: <author name>
Age: <minimum age>
Time: <minimum time>-<maximum time>
Players: <minimum players>-<maximum players>
Price: <price> <currency>
Name:
The name of the board game.Author:
The creator or publisher of the game.Age:
Minimum age requirement for the game.Time:
Expected playtime, with optional range (e.g., 30-60
minutes).Players:
Minimum and maximum player count.Price:
Cost of the game, with optional currency (UAH
, USD
, EUR
).Example:
Name: Chess
Author: Unknown
Age: 6
Time: 10-60
Players: 2
Price: 20 USD
Grammar Definition:
The grammar is defined in grammar.pest
using the Pest parser. It uses rules for:
Name
, Author
, Age
, etc.Data Extraction:
The parser tokenizes input based on these rules and extracts relevant fields. Each game entry is represented as a Pair
object in Pest, which is then converted to a Game
struct using the from_pair
method.
Serialization: The extracted data is serialized into JSON format using the Serde library.
The resulting JSON file contains an array of board games, each represented as an object with the following structure:
[
{
"name": "Chess",
"author": "Unknown",
"age": 6,
"min_time": 10,
"max_time": 60,
"min_players": 2,
"max_players": null,
"price": 20.0
}
]
Parse a file:
cargo run -- <input_file> <output_file>
Example:
cargo run input.txt output.json
Display credits:
cargo run -- --credits
Display help:
cargo run -- --help
Input file:
Name: Catan
Author: Klaus Teuber
Age: 10
Time: 60-120
Players: 3-4
Price: 30 USD
Command:
cargo run input.txt output.json
Output file (output.json
):
[
{
"name": "Catan",
"author": "Klaus Teuber",
"age": 10,
"min_time": 60,
"max_time": 120,
"min_players": 3,
"max_players": 4,
"price": 30.0
}
]
This project leverages:
MIT License