Crate minparser

Crate minparser 

Source
Expand description

Simple parsing tools

This crate is a collection of objects and algorithms shared among different crates that needs to implement a parser.

A Position is an object representing a position inside some file, it contains a line index and a column index. The main role of a Position object is to uniquely identify a single character or a token inside a file in order to allow the user to easily find it.

All the parsing structures in this library take a lifetime parameter 'a which represents the lifetime of the parsed string. Indeed, this crate tries to avoid any sort of allocation by keeping all the deducced information on the parsed string. If you need to dispose the parsed string at some point of your program or you do not want to put a lifetime parameter in your custom structures then you can just convert any returned &'a str into a String.

The View<'a> object is a structure that contains a reference to a string and the position of its first character with respect to a file. It contains several useful parsing methods, the most important of them is match_tool that applies a parsing strategy to the underlying string represented by an argument implementing the Tool<'a> trait.

You can find several useful objects implementing the Tool trait in tools, moretools and utils submodules.

§Usage examples

use minparser::prelude::*;
let (mtc, step) = View::from("My string   value").match_tool_string(&"My string").unwrap();
assert_eq!(mtc, "My string");
assert_eq!(step.get_view(), "   value"); 
use minparser::prelude::*;
let (data, step) = View::new("9180029a")
.match_tool_data(&RepeatAny::new_unbounded(Predicate::new(|c : char| c.is_ascii_digit()), TrueTool)).unwrap();
assert_eq!(data, 7);
assert_eq!(step.get_view(), "a");

§Documented features

A list of features you can optionally enable. None of these are enabled by default:

  • alloc: Links the library with the alloc crate and enable associated functions that works with Vec and other containers in alloc;
  • nightly-features: Enable experimental features. Warning: it requires nightly builds and breaking changes may be introduced even at minor releases.

Modules§

moretools
Additional parsing strategies.
pos
Objects and utilities to keep track of positions inside a text file.
prelude
Crate prelude
tools
Parsing tools.
utils
Other useful parsing tools.

Macros§

always_impl
Automatically implements Tool for an object without templates implementing AlwaysTool.