summary refs log blame commit diff stats
path: root/src/pattern.rs
blob: 3a8c91fb2b146a1aeb7bdc8c53c3eed239ae3cf3 (plain) (tree)
1
2
3
4
5
6
7
8
9
10

                                             
 


                               



                        
                     

                                
                         
                                
                           
 

                                  

 
                               
                                          
                                   
                       

                                                      
                                       


                                
     
                 
                                              


          






                                                                              

     
// Copyright (C) 2021-2022 Soni L.
// SPDX-License-Identifier: MIT OR Apache-2.0

use std::borrow::Borrow;
use std::collections::BTreeMap;

use serde::Deserialize;
use serde::Deserializer;
use serde::Serialize;

use crate::Predicate;
use crate::errors::PatternError;
use crate::parser::parse;
//use crate::vm::Matcher;
use crate::vm::PatternConstants;
//use crate::vm::MAX_CALLS;

pub struct Pattern<O: Serialize> {
    consts: PatternConstants<O>,
}

impl<O: Serialize> Pattern<O> {
    /// Compiles the input into a pattern.
    pub fn compile<'s, PKey, OKey>(
        input: &'s str,
        preds: Option<BTreeMap<PKey, Box<Predicate>>>,
        objs: Option<BTreeMap<OKey, O>>
    ) -> Result<Self, PatternError<'s>>
    where
        PKey: Borrow<str> + Ord,
        OKey: Borrow<str> + Ord,
    {
        Ok(Self {
            consts: parse(input, preds, objs)?
        })
    }

    /// Matches the pattern against an input.
    pub fn deserialize<'de, Der, De>(&self, de: Der) -> Result<De, Der::Error>
    where
        Der: Deserializer<'de>,
        De: Deserialize<'de>,
    {
        todo!()
    }
}