1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#![allow(dead_code)] //! rcombinators is a parser combinator library without special magic. It aims to be both easy to //! use and reasonably fast, without using too much special syntax or macros. //! //! You will notice two kinds of parsers that however differ only in minor aspects: //! //! * Ones starting with a capital letter are `struct`s (such as `Int`, `Sequence`). You can //! create them using `ParserName::new()`, or a specialized constructor method. //! * Ones starting with a lower case letter (and in snake case, such as `string_of`). Those are //! functions returning `Parser` objects combined from one or more elementary parsers. //! //! The resulting objects implementing the `Parser` trait are identical to use. //! //! Note that not all primitives and combinators are exported at the crate level! Only "important" //! ones are. //! //! Here's a short example of how to use it: //! //! ``` //! use rcombinators::combinators; //! use rcombinators::primitives; //! use rcombinators::ParseState; //! use rcombinators::Parser; //! //! // Goal: Parse the string between the parentheses, and then the float. //! let mut ps = ParseState::new("(a1b3c4) -1.25e-1"); //! //! let mut some_string = combinators::Alternative::new( //! (primitives::StringParser::new("xyz"), //! primitives::string_of("abcde12345", //! combinators::RepeatSpec::Min(1)))); //! let mut in_parens = combinators::Sequence::new( //! (primitives::StringParser::new("("), //! some_string, //! primitives::StringParser::new(")"))); //! assert_eq!(Ok( //! ("(".to_string(), //! "a1b3c4".to_string(), //! ")".to_string())), in_parens.parse(&mut ps)); //! //! // You can continue using a ParseState, for example when implementing your own parsers. //! let _ = primitives::whitespace().parse(&mut ps); //! // Parsers returned by functions such as float() should be cached when used more frequently. //! // This saves time due to not needing to construct the parsers repeatedly. //! assert_eq!(Ok(-0.125), primitives::float().parse(&mut ps)); //! ``` #[allow(unused_imports)] #[macro_use] extern crate time_test; pub mod combinators; pub mod parser; pub mod primitives; mod state; pub use combinators::{Alternative, Maybe, PartialSequence, Repeat, Sequence, Then, Transform}; pub use parser::{execerr, ParseResult, Parser}; pub use primitives::{float, string_none_of, string_of, whitespace, Int, StringParser}; pub use state::ParseState;