pub struct Variable { /* private fields */ }
Implementations§
Source§impl Variable
impl Variable
Sourcepub fn new(scope: usize, index: usize) -> Self
pub fn new(scope: usize, index: usize) -> Self
Create a variable, where we already know the scope and index it will be bound to
Sourcepub fn new_dynamic(name: &str) -> Self
pub fn new_dynamic(name: &str) -> Self
Create a dynamic variable, which will be bound to the first scope that uses it
Warning: this is not stable or tested yet. This implementation is still incomplete.
Sourcepub fn try_scope(&self) -> GritResult<u16>
pub fn try_scope(&self) -> GritResult<u16>
Try to get the scope of the variable, if it has been bound to a scope.
If the variable has not been bound to a scope, return an error.
When possible, prefer to use get_scope()
instead, which will initialize the variable’s scope if it is not already bound.
Sourcepub fn try_index(&self) -> GritResult<u16>
pub fn try_index(&self) -> GritResult<u16>
Try to get the index of the variable, if it has been bound to an index.
If the variable has not been bound to an index, return an error.
When possible, prefer to use get_index()
instead, which will initialize the variable’s index if it is not already bound.
Sourcepub fn get_scope<Q: QueryContext>(
&self,
state: &mut State<'_, Q>,
) -> GritResult<u16>
pub fn get_scope<Q: QueryContext>( &self, state: &mut State<'_, Q>, ) -> GritResult<u16>
Get the scope of the variable, initializing it if it is not already bound.
Sourcepub fn get_index<Q: QueryContext>(
&self,
state: &mut State<'_, Q>,
) -> GritResult<u16>
pub fn get_index<Q: QueryContext>( &self, state: &mut State<'_, Q>, ) -> GritResult<u16>
Get the index of the variable, initializing it if it is not already bound.
pub fn get_pattern_or_resolved<'a, 'b, Q: QueryContext>( &self, state: &'b State<'a, Q>, ) -> GritResult<Option<PatternOrResolved<'a, 'b, Q>>>
pub fn get_pattern_or_resolved_mut<'a, 'b, Q: QueryContext>( &self, state: &'b mut State<'a, Q>, ) -> GritResult<Option<PatternOrResolvedMut<'a, 'b, Q>>>
pub fn file_name() -> Self
pub fn is_file_name(&self) -> bool
pub fn is_program(&self) -> bool
Sourcepub fn is_probably_match(&self) -> bool
pub fn is_probably_match(&self) -> bool
We auto-insert a $match variable during auto-wrap, which we can usually treat as being usable in the program body
pub fn text<'a, Q: QueryContext>( &self, state: &State<'a, Q>, lang: &Q::Language<'a>, ) -> GritResult<Cow<'a, str>>
Trait Implementations§
Source§impl<Q: QueryContext> Matcher<Q> for Variable
impl<Q: QueryContext> Matcher<Q> for Variable
fn execute<'a>( &'a self, resolved_pattern: &Q::ResolvedPattern<'a>, state: &mut State<'a, Q>, context: &'a Q::ExecContext<'a>, logs: &mut AnalysisLogs, ) -> GritResult<bool>
Auto Trait Implementations§
impl Freeze for Variable
impl RefUnwindSafe for Variable
impl Send for Variable
impl Sync for Variable
impl Unpin for Variable
impl UnwindSafe for Variable
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more