b2285ce0e0
Just's first parser performed both parsing, i.e the transformation of a token stream according to the language grammar, and a number of consistency checks and analysis passes. This made parsing and analysis quite complex, so this diff introduces a new, much cleaner `Parser`, and moves existing analysis into a dedicated `Analyzer`.
57 lines
1.3 KiB
Rust
57 lines
1.3 KiB
Rust
use crate::common::*;
|
|
|
|
pub(crate) trait RangeExt<T> {
|
|
fn range_contains(&self, i: &T) -> bool;
|
|
}
|
|
|
|
impl<T> RangeExt<T> for Range<T>
|
|
where
|
|
T: PartialOrd,
|
|
{
|
|
fn range_contains(&self, i: &T) -> bool {
|
|
i >= &self.start && i < &self.end
|
|
}
|
|
}
|
|
|
|
impl<T> RangeExt<T> for RangeInclusive<T>
|
|
where
|
|
T: PartialOrd,
|
|
{
|
|
fn range_contains(&self, i: &T) -> bool {
|
|
i >= self.start() && i <= self.end()
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
#[test]
|
|
fn exclusive() {
|
|
assert!(!(0..0).range_contains(&0));
|
|
assert!(!(0..0).range_contains(&0));
|
|
assert!(!(1..10).range_contains(&0));
|
|
assert!(!(1..10).range_contains(&10));
|
|
assert!(!(1..10).range_contains(&0));
|
|
assert!(!(1..10).range_contains(&10));
|
|
assert!((0..1).range_contains(&0));
|
|
assert!((0..1).range_contains(&0));
|
|
assert!((10..20).range_contains(&15));
|
|
assert!((10..20).range_contains(&15));
|
|
}
|
|
|
|
#[test]
|
|
fn inclusive() {
|
|
assert!(!(0..=10).range_contains(&11));
|
|
assert!(!(1..=10).range_contains(&0));
|
|
assert!(!(5..=10).range_contains(&4));
|
|
assert!((0..=0).range_contains(&0));
|
|
assert!((0..=1).range_contains(&0));
|
|
assert!((0..=10).range_contains(&0));
|
|
assert!((0..=10).range_contains(&10));
|
|
assert!((0..=10).range_contains(&7));
|
|
assert!((1..=10).range_contains(&10));
|
|
assert!((10..=20).range_contains(&15));
|
|
}
|
|
}
|