Crates.io | person_struct_parser |
lib.rs | person_struct_parser |
version | 1.3.1 |
source | src |
created_at | 2023-11-11 19:27:22.177087 |
updated_at | 2023-11-15 11:23:01.12283 |
description | Rust parser for person struct |
homepage | |
repository | |
max_upload_size | |
id | 1032352 |
size | 24,721 |
Person_struct_parser(PSP) is a parsing library for parsing a String into a person object.
person_struct_parser::person_module::Person
) for containing the information about a person(name,age,city,zip,phone_number)pub struct Person {
///name of the person
pub name: String,
///age of the person
pub age: u32,
///city where the person lives
pub city: String,
///zip
pub zip: u32,
///phone number
pub phone: String
}
person_struct_parser::person_module::normalize
implemented for Person to reduce object data to normal form:pub fn normalize(&mut self) -> &mut Self
person_struct_parser::person_module::parse
is implemented for Person, it's main method for parsing String into the Person object with normalization:pub fn parse(string: &str) -> anyhow::Result<Person>
std::fmt::Display
is implemented for Person
Grammar for parsing:
low_alpha = {'a'..'z'}
high_alpha = {'A'..'Z'}
digit = {'0'..'9'}
name = {high_alpha ~ low_alpha+}
age = {digit{1,4}}
city = {high_alpha ~ (low_alpha+ | (low_alpha+ ~ ('-' | ' ') ~ low_alpha+))}
zip = {digit{5}}
phone_number = {'+' ~ (digit{12} | digit{10})}
person = {name ~ ' ' ~ age ~ ' ' ~ city ~ zip ~ ' ' ~ phone_number}
Roman-21-Paris54586 +380546548577
:let mut person = Person{name:String::from("RoMAn"),age:21,city:String::from("PaRiS"),zip:54586,phone:"+380546548577"};
println!("{}",person.normalize());
Roman-21-Paris54586 +380426458777
because of parsing and normalization after:println!("{}",parse("-Ro*Ma/N//2*-1..PaR*I-s-54gh5h-h8ghj6 --+3804-2/64/58-*777").unwrap());
cargo run -- -i your_file_name.txt
in command prompt to parse the content of your file. If there is a problem it will parse the appropriate default file. The result will be placed in Result.txt Also there are more commands - try cargo run -- --help
for more info.There is a custom error enum type using thiserror
crate for parsing. For more look the documentation