#![allow(dead_code)]
pub use p_tokens::{PToken, PTokenAt, PTokenRange, PTokenRangeTo};
use std::{
collections::{BTreeMap, HashSet},
hash::Hash,
};
use type_map::TypeMap;
mod p_tokens;
struct PTokenLine {
tokens: PTokenRange,
context_information: TypeMap,
annotations: BTreeMap<
PTokenAt,
BTreeMap< PTokenRangeTo,
TypeMap,
>,
>,
}
pub enum AcceptResult<S, A> {
Next(S, PTokenRangeTo),
AssignToSpan(A),
AssignUpTo(A, PTokenRangeTo),
}
struct StepContext<'a> {
start: &'a PTokenAt,
current: &'a PToken,
attributes: &'a PTokenLine,
}
impl<'a> StepContext<'a> {
fn current_has<T: 'static>(&self) -> Option<T> {
unimplemented!()
}
fn current_within<T: 'static>(&self) -> Vec<(T, PTokenAt, PTokenRangeTo)> {
unimplemented!()
}
}
trait Recognizer {
type State;
type Attribute;
fn start(&self, next: &StepContext) -> Vec<AcceptResult<Self::State, Self::Attribute>>;
fn next(
&self,
state: &Self::State,
next: &StepContext,
) -> Vec<AcceptResult<Self::State, Self::Attribute>>;
}
impl PTokenLine {
fn apply<R, S>(&mut self, _rule: R)
where
R: Recognizer<State = S>,
{
todo!("actually try to execute the rule over the span")
}
}
struct RecognizedLocation {
query: String,
country: Option<String>,
}
mod numbers {
use super::*;
#[derive(Default)]
struct NumberRecognizer(());
struct RecognizedNumber(rust_decimal::Decimal);
enum State {
BeforeDecimal(String),
AfterDecimal(String, String),
}
impl Recognizer for NumberRecognizer {
type State = State;
type Attribute = RecognizedNumber;
fn start(&self, next: &StepContext) -> Vec<AcceptResult<Self::State, Self::Attribute>> {
}
fn next(
&self,
state: &Self::State,
next: &StepContext,
) -> Vec<AcceptResult<Self::State, Self::Attribute>> {
todo!()
}
}
}
mod money {
use super::*;
enum CurrencySymbol {
USD,
}
enum LastPunctuation {
DecimalPoint,
NumberVisualSeparator,
}
enum State {
SymbolStart(CurrencySymbol),
SymbolWithNumbersLeftOfDecimal {
currency: CurrencySymbol,
current_left_of_decimal: usize,
parsed_up_to: PTokenRangeTo,
last_punctuation: Option<LastPunctuation>,
},
}
enum MoneyAmount {
USDPennies(usize),
}
pub struct RecognizedMoney {
query: String,
amount: MoneyAmount,
}
#[derive(Default)]
struct MoneyRecognizer(());
impl Recognizer for MoneyRecognizer {
type State = State;
type Attribute = RecognizedMoney;
fn start(&self, next: &StepContext) -> Vec<AcceptResult<Self::State, Self::Attribute>> {
}
fn next(
&self,
state: &Self::State,
next: &StepContext,
) -> Vec<AcceptResult<Self::State, Self::Attribute>> {
todo!()
}
}
}
#[allow(dead_code)]
fn t() {
}
fn set1<T: Eq + Hash>(z: T) -> HashSet<T> {
std::iter::once(z).collect()
}
fn set2<T: Eq + Hash>(y: T, z: T) -> HashSet<T> {
vec![y, z].into_iter().collect()
}
fn set3<T: Eq + Hash>(x: T, y: T, z: T) -> HashSet<T> {
vec![x, y, z].into_iter().collect()
}