minparser/
lib.rs

1/*
2 * Minparser Simple parsing functions
3 *
4 * Copyright (C) 2024-2025 Paolo De Donato
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 */
19
20//! Simple parsing tools
21//!
22//! This crate is a collection of objects and algorithms shared among different crates that needs
23//! to implement a parser. 
24//!
25//! A [``Position``](pos::Position) is an object that identifies a (textual) *file* and a position inside it,
26//! represented as a *line index* and a *column index*. The main role of a `Position` object is to
27//! uniquely identify a single character or a token inside a file in order to allow the
28//! user to easily find it.
29//!
30//! A [``View<'a, D, F>``](view::View) can be seen as a suffix of a larger string with the position of
31//! its first character and some data of type `D`. The [``match_tool``](view::View::match_tool) method
32//! can be used to match its prefix with any object implementing the [``ParseTool``](tools::ParseTool) 
33//! trait which represents a pattern that can be satisfied or not by a string.
34//!
35//! Many useful parsing tools can be found in [`tools`] and [`utils`] modules.
36//!
37//! # Usage example
38//! ```
39//! use minparser::prelude::*;
40//! let view = ViewFile::new_default("My string   value");
41//! let (step, mtc) = view.match_tool_string("My string").unwrap();
42//! assert_eq!(mtc, "My string");
43//! assert_eq!(step.get_view(), "   value"); 
44//! let step = step.match_tool(minparser::utils::WhiteTool).unwrap();   // Use the WhiteTool tool to
45//! assert_eq!(step.get_view(), "value");                               //match a sequence of whitespaces
46//! assert!(step.match_tool('a').is_err()); // A missing match is an error
47//! ```
48#![deny(missing_docs)]
49#![no_std]
50#![cfg_attr(feature = "nightly-features", feature(doc_cfg))]
51
52#[cfg(feature = "alloc")]
53extern crate alloc;
54
55pub mod pos;
56pub mod view;
57pub mod tools;
58pub mod parsable;
59pub mod predicates;
60pub mod utils;
61
62/// Crate prelude
63pub mod prelude {
64    pub use crate::pos::*;
65    pub use crate::view::*;
66    pub use crate::tools::*;
67}