pobsd_parser/
lib.rs

1//! pobsd-parser is a parsing library for parsing the PlayOnBSD Database.
2//!
3//! This library provides:
4//! * A [`Parser`] struct handling the parsing
5//! * A [`ParsingMode`] enum to choose between a strict or a relax parsing mode
6//! * A [`ParserResult`] struct to handle parsing with and without error
7//! * A [`Game`] struct representing a game of a database
8//!
9//! ### Examples
10//! Here is a first example loading a file in relaxed mode (by default).
11//! ```no_run
12//! extern crate pobsd_parser;
13//! use pobsd_parser::{Parser, ParserResult};
14//!
15//! // Create a parser
16//! let parser = Parser::default();
17//! // Load the database
18//! let parser_result = parser.load_from_file("/path/to/games.db")
19//!        .expect("Problem trying to open the file");
20//! let games = match parser_result {
21//!        ParserResult::WithoutError(games) => games,
22//!        ParserResult::WithError(games, _) => games,
23//!    };
24//! ```
25//! The parser can also use a strict mode in which it will stop when encountering
26//! a parsing error and returning the games it has processed.
27//! ```no_run
28//! extern crate pobsd_parser;
29//! use pobsd_parser::{Parser, ParserResult, ParsingMode};
30//!
31//! // Create a paser in strict mode
32//! let parser = Parser::new(ParsingMode::Strict);
33//! // Load the database
34//! let parser_result = parser.load_from_file("/path/to/games.db")
35//!        .expect("Problem trying to open the file");
36//! let games = match parser_result {
37//!     ParserResult::WithoutError(games) => games,
38//!     ParserResult::WithError(games, _) => games,
39//! };
40//! ```
41//! The parser can also load from a &str or a String.
42//! ```
43//! extern crate pobsd_parser;
44//! use pobsd_parser::{Parser, ParserResult, ParsingMode};
45//!
46//! let games = r#"Game	AaaaaAAaaaAAAaaAAAAaAAAAA!!! for the Awesome
47//! Cover	AaaaaA_for_the_Awesome_Cover.jpg
48//! Engine
49//! Setup
50//! Runtime	HumblePlay
51//! Store	https://www.humblebundle.com/store/aaaaaaaaaaaaaaaaaaaaaaaaa-for-the-awesome
52//! Hints	Demo on HumbleBundle store page
53//! Genre
54//! Tags
55//! Year	2011
56//! Dev
57//! Pub
58//! Version
59//! Status
60//! Added	1970-01-01
61//! Updated	1970-01-01
62//! IgdbId	12
63//! Game	The Adventures of Mr. Hat
64//! Cover
65//! Engine	godot
66//! Setup
67//! Runtime	godot
68//! Store	https://store.steampowered.com/app/1869200/The_Adventures_of_Mr_Hat/
69//! Hints
70//! Genre	Puzzle Platformer
71//! Tags	indie
72//! Year
73//! Dev	AX-GAME
74//! Pub	Fun Quarter
75//! Version	Early Access
76//! Status	runs (2022-05-13)
77//! Added	2022-05-13
78//! Updated	2022-05-13
79//! IgdbId	13"#;
80//!
81//! let parser = Parser::default();
82//! let games = match parser.load_from_string(games) {
83//!     ParserResult::WithoutError(games) => games,
84//!     // Should not panic since the data are fine
85//!     ParserResult::WithError(_, _) => panic!(),
86//! };
87//!
88//! ```
89#[macro_use]
90extern crate serde_derive;
91extern crate serde_json;
92
93#[macro_use]
94pub(crate) mod parser_macros;
95pub(crate) mod field;
96pub mod game;
97pub mod parser;
98pub(crate) mod split_line;
99pub mod store_links;
100
101pub use self::game::Game;
102pub use self::parser::Parser;
103pub use self::parser::ParserResult;
104pub use self::parser::ParsingMode;
105pub use self::store_links::Store;
106pub use self::store_links::StoreLink;
107pub use self::store_links::StoreLinks;