person_struct_parser
Parser for Rust source code
- GITHUB: https://github.com/DavydKod/person_struct_parser
- CRATES.IO: https://crates.io/crates/person_struct_parser
Person_struct_parser(PSP) is a parsing library for parsing a String into a person object.
- PSP has structure Person(
person_struct_parser::person_module::Person) for containing the information about a person(name,age,city,zip) and zip_is_ua(true if zip is UA)
- There is a function
person_struct_parser::person_module::normalizeimplemented for Person to reduce object data to normal form:
- Function
person_struct_parser::person_module::parseis implemented for Person, it's main method for parsing String into the Person object with normalization:
-
std::fmt::Displayis 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}}
person = {name ~ ' ' ~ age ~ ' ' ~ city ~ zip}
Example
- Normalization. To normalize person object. Next example will print
Roman-21-Paris54586:
let mut person = Person;
println!;
- Parsing. Next example will print
Roman-21-Paris54586because of parsing and normalization after:
println!;
- CLI. You can execute
cargo run -- -i your_file_name.txtin command prompt to parse the content of your file. If there is a problem it will parse the appropriate default file. Also there are more commands - trycargo run -- --helpfor more info.
Custom Error
There is a custom error enum type using thiserror crate for parsing. For more look the documentation