Skip to main content

FnParser

Struct FnParser 

Source
pub struct FnParser<I: View<V = Seq<u8>>, O: DeepView, Spec: SpecParser<PVal = O::V>, Exec: Fn(&I) -> PResult<O>> {
    pub exec_fn: Exec,
    pub spec_fn: Ghost<Spec>,
    pub _marker: PhantomData<(I, O)>,
}
Expand description

Pairs an executable parser closure with a ghost specification parser.

Fields§

§exec_fn: Exec§spec_fn: Ghost<Spec>§_marker: PhantomData<(I, O)>

Implementations§

Source§

impl<I, O, Spec, Exec> FnParser<I, O, Spec, Exec>
where I: View<V = Seq<u8>>, O: DeepView, Spec: Productive<PVal = O::V>, Exec: Fn(&I) -> PResult<O>,

Source

pub exec fn new(exec_fn: Exec, Ghost(spec_fn): Ghost<Spec>) -> parser : Self

requires
spec_fn.safe_inv(),
spec_fn.productive_inv(),
forall |i: &I| #[trigger] call_requires(exec_fn, (i,)),
forall |i: &I, r: PResult<O>| {
    #[trigger] call_ensures(exec_fn, (i,), r)
        ==> parse_matches_spec(r, spec_fn.spec_parse(i@))
},
ensures
parser.exec_inv(),
parser.safe_inv(),
parser.productive_inv(),
parser.spec_fn == spec_fn,

Constructs a safe, productive parser callback with a ghost specification.

Trait Implementations§

Source§

impl<I, O, Spec, Exec> Parser<I> for FnParser<I, O, Spec, Exec>
where I: View<V = Seq<u8>>, O: DeepView, Spec: SpecParser<PVal = O::V>, Exec: Fn(&I) -> PResult<O>,

Source§

open spec fn exec_inv(&self) -> bool

{
    &&& forall |i: &I| #[trigger] call_requires(self.exec_fn, (i,))
    &&& forall |i: &I, r: PResult<O>| {
        #[trigger] call_ensures(self.exec_fn, (i,), r)
            ==> {
                let Ghost(spec_fn) = self.spec_fn;
                parse_matches_spec(r, spec_fn.spec_parse(i@))
            }
    }

}
Source§

exec fn parse(&self, ibuf: &I) -> r : PResult<O>

Source§

type PT = O

Executable value returned by this parser.
Source§

impl<I, O, Spec, Exec> Productive for FnParser<I, O, Spec, Exec>
where I: View<V = Seq<u8>>, O: DeepView, Spec: Productive<PVal = O::V>, Exec: Fn(&I) -> PResult<O>,

Source§

open spec fn productive_inv(&self) -> bool

{
    let Ghost(spec_fn) = self.spec_fn;
    spec_fn.productive_inv()
}
Source§

proof fn lemma_productive(&self, input: Seq<u8>)

Source§

impl<I, O, Spec, Exec> SafeParser for FnParser<I, O, Spec, Exec>
where I: View<V = Seq<u8>>, O: DeepView, Spec: SafeParser<PVal = O::V>, Exec: Fn(&I) -> PResult<O>,

Source§

open spec fn safe_inv(&self) -> bool

{
    let Ghost(spec_fn) = self.spec_fn;
    spec_fn.safe_inv()
}
Source§

proof fn lemma_parse_safe(&self, ibuf: Seq<u8>)

Source§

impl<I, O, Spec, Exec> SpecParser for FnParser<I, O, Spec, Exec>
where I: View<V = Seq<u8>>, O: DeepView, Spec: SpecParser<PVal = O::V>, Exec: Fn(&I) -> PResult<O>,

Source§

open spec fn spec_parse(&self, ibuf: Seq<u8>) -> Option<(int, Self::PVal)>

{
    let Ghost(spec_fn) = self.spec_fn;
    spec_fn.spec_parse(ibuf)
}
Source§

type PVal = <O as DeepView>::V

The type of parsed values.

Auto Trait Implementations§

§

impl<I, O, Spec, Exec> Freeze for FnParser<I, O, Spec, Exec>
where Exec: Freeze,

§

impl<I, O, Spec, Exec> RefUnwindSafe for FnParser<I, O, Spec, Exec>

§

impl<I, O, Spec, Exec> Send for FnParser<I, O, Spec, Exec>
where Exec: Send, I: Send, O: Send,

§

impl<I, O, Spec, Exec> Sync for FnParser<I, O, Spec, Exec>
where Exec: Sync, I: Sync, O: Sync,

§

impl<I, O, Spec, Exec> Unpin for FnParser<I, O, Spec, Exec>
where Exec: Unpin, Spec: Unpin, I: Unpin, O: Unpin,

§

impl<I, O, Spec, Exec> UnsafeUnpin for FnParser<I, O, Spec, Exec>
where Exec: UnsafeUnpin,

§

impl<I, O, Spec, Exec> UnwindSafe for FnParser<I, O, Spec, Exec>
where Exec: UnwindSafe, Spec: UnwindSafe, I: UnwindSafe, O: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, VERUS_SPEC__A> FromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: From<T>,

§

fn obeys_from_spec() -> bool

§

fn from_spec(v: T) -> VERUS_SPEC__A

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T, VERUS_SPEC__A> IntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: Into<T>,

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> T

§

impl<T, U> IntoSpecImpl<U> for T
where U: From<T>,

§

fn obeys_into_spec() -> bool

§

fn into_spec(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, VERUS_SPEC__A> TryFromSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryFrom<T>,

§

fn obeys_try_from_spec() -> bool

§

fn try_from_spec( v: T, ) -> Result<VERUS_SPEC__A, <VERUS_SPEC__A as TryFrom<T>>::Error>

Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T, VERUS_SPEC__A> TryIntoSpec<T> for VERUS_SPEC__A
where VERUS_SPEC__A: TryInto<T>,

§

fn obeys_try_into_spec() -> bool

§

fn try_into_spec(self) -> Result<T, <VERUS_SPEC__A as TryInto<T>>::Error>

§

impl<T, U> TryIntoSpecImpl<U> for T
where U: TryFrom<T>,

§

fn obeys_try_into_spec() -> bool

§

fn try_into_spec(self) -> Result<U, <U as TryFrom<T>>::Error>

§

impl<A> SpecEq<&A> for A
where A: ?Sized,

§

impl<A> SpecEq<&mut A> for A
where A: ?Sized,

§

impl<A> SpecEq<A> for A
where A: ?Sized,

§

impl<A> SpecEq<Ghost<A>> for A

§

impl<A> SpecEq<Tracked<A>> for A