summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordfhoughton <dfhoughton@gmail.com>2019-01-05 16:20:29 -0500
committerdfhoughton <dfhoughton@gmail.com>2019-01-05 16:20:29 -0500
commitb92350ef6a37fd5e388b77e7eef202878d964922 (patch)
tree0ad7bab2354f6884f719b39bc6e5d9615aec96fa
parent4d885eff8c4c745348126e96cf7cf46d478f30bb (diff)
downloadtwo-timer-b92350ef6a37fd5e388b77e7eef202878d964922.zip
made space optional before era suffix
-rw-r--r--Cargo.lock6
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs15
-rw-r--r--tests/tests.rs18
4 files changed, 31 insertions, 10 deletions
diff --git a/Cargo.lock b/Cargo.lock
index b79a3e5..157c006 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -56,7 +56,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "pidgin"
-version = "0.2.0"
+version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -112,7 +112,7 @@ version = "1.0.0"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "pidgin 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
+ "pidgin 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -159,7 +159,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16"
"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea"
"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1"
-"checksum pidgin 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ebfb7c2a7cadeeac248ecfcf74e514342bede5709780accf6b4225e059745f20"
+"checksum pidgin 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7de3efd6e9f57f6d65f7d6ec34b47f0e91082e1042b4979929843802d1ce130d"
"checksum redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "679da7508e9a6390aeaf7fbd02a800fdc64b73fe2204dd2c8ae66d22d9d5ad5d"
"checksum regex 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ee84f70c8c08744ea9641a731c7fadb475bf2ecc52d7f627feb833e0b3990467"
"checksum regex-syntax 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fbc557aac2b708fe84121caf261346cc2eed71978024337e42eb46b8a252ac6e"
diff --git a/Cargo.toml b/Cargo.toml
index 0a2cfa8..bdd210a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -15,7 +15,7 @@ edition = "2018"
panic = "abort"
[dependencies]
-pidgin = "0.2"
+pidgin = "0.3"
lazy_static = "1.2"
chrono = "0.4"
regex = "1" \ No newline at end of file
diff --git a/src/lib.rs b/src/lib.rs
index 0c44b73..0a69014 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -181,11 +181,11 @@ extern crate lazy_static;
extern crate chrono;
use chrono::naive::{NaiveDate, NaiveDateTime};
use chrono::{Datelike, Duration, Local, Timelike, Weekday};
-use pidgin::{Match, Matcher};
+use pidgin::{Grammar, Match, Matcher};
use regex::Regex;
lazy_static! {
- static ref MATCHER: Matcher = grammar!{
+ pub static ref GRAMMAR: Grammar = grammar!{
(?ibBw)
TOP -> r(r"\A") <something> r(r"\z")
@@ -243,10 +243,10 @@ lazy_static! {
.collect::<Vec<_>>()
]
n_year => r(r"\b(?:[1-9][0-9]{0,4}|0)\b")
- suffix_year => r(r"\b[1-9][0-9]{0,4}\b")
+ suffix_year => r(r"\b[1-9][0-9]{0,4}")
year_suffix => <ce> | <bce>
- ce => (?-i) [["ce", "c.e.", "ad", "a.d.", "CE", "C.E.", "AD", "A.D."]]
- bce => (?-i) [["bce", "b.c.e.", "bc", "b.c.", "BCE", "B.C.E.", "BC", "B.C."]]
+ ce => (?-ib) [["ce", "c.e.", "ad", "a.d.", "CE", "C.E.", "AD", "A.D."]]
+ bce => (?-ib) [["bce", "b.c.e.", "bc", "b.c.", "BCE", "B.C.E.", "BC", "B.C."]]
n_day => [
(1..=31)
.into_iter()
@@ -311,7 +311,10 @@ lazy_static! {
"ever after",
"the last syllable of recorded time",
]]
- }.matcher().unwrap();
+ };
+}
+lazy_static! {
+ pub static ref MATCHER: Matcher = GRAMMAR.matcher().unwrap();
}
/// A collection of parameters that can influence the interpretation
diff --git a/tests/tests.rs b/tests/tests.rs
index 31ef9fb..c77eb1a 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -852,6 +852,24 @@ fn april_3_25_ad() {
}
#[test]
+fn april_3_25bc() {
+ let d1 = NaiveDate::from_ymd(-24, 4, 3).and_hms(0, 0, 0);
+ let d2 = d1 + Duration::days(1);
+ let (start, end, _) = parse("April 3, 25BC", None).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
+fn april_3_25ad() {
+ let d1 = NaiveDate::from_ymd(25, 4, 3).and_hms(0, 0, 0);
+ let d2 = d1 + Duration::days(1);
+ let (start, end, _) = parse("April 3, 25AD", None).unwrap();
+ assert_eq!(d1, start);
+ assert_eq!(d2, end);
+}
+
+#[test]
fn this_weekend() {
let now = NaiveDate::from_ymd(1969, 5, 6).and_hms(0, 0, 0);
let d1 = NaiveDate::from_ymd(1969, 5, 10).and_hms(0, 0, 0);