Skip to main content

Predicate

Enum Predicate 

Source
pub enum Predicate {
    Contains {
        capture: u32,
        values: Vec<String>,
    },
    Ancestor {
        capture: u32,
        kinds: Vec<String>,
        parent: bool,
        negative: bool,
    },
    Offset {
        capture: u32,
        offsets: [isize; 4],
    },
}
Expand description

A compiled custom predicate or capture-offset directive.

Variants§

§

Contains

Require captured text to contain at least one literal.

Fields

§capture: u32

Capture index to inspect or adjust.

§values: Vec<String>

Literal substrings to search for.

§

Ancestor

Test parent or ancestor node kinds, optionally negating the result.

Fields

§capture: u32

Capture index to inspect or adjust.

§kinds: Vec<String>

Node kinds that satisfy the structural test.

§parent: bool

Inspect only the immediate parent when true.

§negative: bool

Accept when no inspected node matches a kind.

§

Offset

Adjust capture boundaries by row and byte-column offsets.

Fields

§capture: u32

Capture index to inspect or adjust.

§offsets: [isize; 4]

Start row/column and end row/column adjustments, in that order.

Implementations§

Source§

impl Predicate

Source

pub fn compile(operator: &str, arguments: Vec<Argument>) -> Result<Self, Error>

Compile a custom-predicate operator and literal arguments.

§Errors

Returns Error::Query for unsupported operators or malformed arguments.

Source

pub fn accepts(&self, matched: &Match, source: &str) -> bool

Test all matching captures before applying offsets.

A predicate with no matching captures is accepted. Offset directives do not filter matches. Self::apply adjusts their ranges.

Source

pub fn apply(&self, matched: &mut Match, source: &str) -> Result<(), Error>

Apply offset directives to matching captures. Other predicates do nothing.

§Errors

Returns Error::InvalidRange when an offset leaves the source or splits a UTF-8 character.

Auto Trait Implementations§

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.

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.

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
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.