Skip to content

Commit

Permalink
Rename back to Parser, simplify sample code a bit.
Browse files Browse the repository at this point in the history
  • Loading branch information
waywardmonkeys committed Jul 23, 2016
1 parent 6c4b8f5 commit 25dc3ca
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
10 changes: 3 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,14 @@
//! First, you'll want to construct a parser:
//!
//! ```
//! use humanize::HumanizedParser;
//!
//! let parser = HumanizedParser::new();
//! let parser = humanize::Parser::new();
//! ```
//!
//! Then, you can use that parser to examine some input. In the typical
//! case, you can invoke a type-specific parse method like `parse_boolean`.
//!
//! ```
//! # use humanize::HumanizedParser;
//! #
//! # let parser = HumanizedParser::new();
//! let parser = humanize::Parser::new();
//! let enabled = parser.parse_boolean("on").unwrap_or(false);
//! assert_eq!(enabled, true);
//! ```
Expand Down Expand Up @@ -75,4 +71,4 @@ extern crate language_tags;
pub mod matchers;
mod parser;

pub use parser::HumanizedParser;
pub use parser::Parser;
4 changes: 2 additions & 2 deletions src/matchers/english/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
// much better and actually work correctly. :)

use matchers::*;
use parser::HumanizedParser;
use parser::Parser;

/// Register matchers for English expressions for boolean values.
///
/// This doesn't need to be invoked directly typically. This will
/// be called by `humanize::matchers::english::register`.
pub fn register(parser: &mut HumanizedParser) {
pub fn register(parser: &mut Parser) {
parser.register_matcher(Matcher {
name: "English Booleans",
language: langtag!(en),
Expand Down
6 changes: 3 additions & 3 deletions src/matchers/english/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

//! English Humanization
use parser::HumanizedParser;
use parser::Parser;

pub mod boolean;
// pub mod ordinal;

/// Register all of the English language matchers.
///
/// This doesn't need to be invoked directly typically. This will
/// be called when creating a default `HumanizedParser`.
pub fn register(parser: &mut HumanizedParser) {
/// be called when creating a default `Parser`.
pub fn register(parser: &mut Parser) {
boolean::register(parser);
}
2 changes: 1 addition & 1 deletion src/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub enum HumanValue {
/// A `Match` result is obtained by calling [`parse`] on
/// some input text. They are created by [`Matcher`]s.
///
/// [`parse`]: ../struct.HumanizedParser.html#method.parse
/// [`parse`]: ../struct.Parser.html#method.parse
/// [`Matcher`]: struct.Matcher.html
#[derive(Debug)]
pub struct Match {
Expand Down
12 changes: 6 additions & 6 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@ use matchers::*;
/// by default when the parser is created. A parser without pre-installed
/// matchers can be created with `new_without_default_matchers`. Additional
/// or custom matchers can be added with `register_matcher`.
pub struct HumanizedParser<'p> {
pub struct Parser<'p> {
/// The matchers which have been registered with this parser.
///
/// Use `HumanizedParser.register_matcher` to add a new matcher.
/// Use `Parser.register_matcher` to add a new matcher.
matchers: Vec<Matcher<'p>>,

/// The language being supported by this parser.
language: LanguageTag,
}

impl<'p> HumanizedParser<'p> {
impl<'p> Parser<'p> {
/// Construct a new parser, including the default matchers.
pub fn new() -> Self {
Default::default()
}

/// Construct a new parser, but without any of the default matchers.
pub fn new_without_default_matchers() -> Self {
HumanizedParser {
Parser {
matchers: vec![],
language: Default::default(),
}
Expand Down Expand Up @@ -84,9 +84,9 @@ impl<'p> HumanizedParser<'p> {
}
}

impl<'p> Default for HumanizedParser<'p> {
impl<'p> Default for Parser<'p> {
fn default() -> Self {
let mut p = HumanizedParser {
let mut p = Parser {
matchers: vec![],
language: Default::default(),
};
Expand Down

0 comments on commit 25dc3ca

Please sign in to comment.