Rust

scanner

Module

The matching engine for timelib's re2c scanner: a Thompson NFA built from the rule definitions of parse_date.re, simulated to find what the re2c DFA finds: the longest match over all rules, the earliest rule on a tie.

The simulation is cached as a lazily built DFA (each set of NFA states seen becomes a DFA state, each transition is computed once), so a format seen before is scanned at one table lookup per byte.

Contents

use php_std::datetime::scanner::ByteSet;
Rust
pub struct ByteSet([u64; 4])

A set of bytes.

use php_std::datetime::scanner::Lazy;
Rust
pub struct Lazy(OnceLock<Nfa>, fn() -> Vec<P>)

A lazily built NFA.

use php_std::datetime::scanner::Nfa;
Rust
pub struct Nfa

All rules compiled into one NFA.

use php_std::datetime::scanner::P;
Rust
pub enum P

A pattern (a re2c regular expression).

use php_std::datetime::scanner::alt;
Rust
pub fn alt(ps: Vec<P>) -> P

A pattern matching any one of ps.

use php_std::datetime::scanner::ci;
Rust
pub fn ci(s: &str) -> P

'...': an ASCII case-insensitive literal.

use php_std::datetime::scanner::digit;
Rust
pub fn digit() -> P

A pattern matching one ASCII digit.

use php_std::datetime::scanner::lit;
Rust
pub fn lit(s: &str) -> P

"...": a case-sensitive literal.

use php_std::datetime::scanner::opt;
Rust
pub fn opt(p: P) -> P

A pattern matching p or nothing.

use php_std::datetime::scanner::plus;
Rust
pub fn plus(p: P) -> P

A pattern matching p one or more times.

use php_std::datetime::scanner::range;
Rust
pub fn range(a: u8, b: u8) -> P

[a-b].

use php_std::datetime::scanner::ranges;
Rust
pub fn ranges(rs: &[(u8, u8)]) -> P

A union of byte ranges.

use php_std::datetime::scanner::rep;
Rust
pub fn rep(p: P, min: u32, max: u32) -> P

A pattern matching p from min to max times.

use php_std::datetime::scanner::seq;
Rust
pub fn seq(ps: Vec<P>) -> P

A pattern matching each of ps in turn.

use php_std::datetime::scanner::set;
Rust
pub fn set(chars: &str) -> P

[...] of the listed bytes.

use php_std::datetime::scanner::star;
Rust
pub fn star(p: P) -> P

A pattern matching p zero or more times.