Struct sqruff_lib::core::parser::markers::PositionMarker

source ·
pub struct PositionMarker {
    pub source_slice: Range<usize>,
    pub templated_slice: Range<usize>,
    pub templated_file: TemplatedFile,
    pub working_line_no: usize,
    pub working_line_pos: usize,
}
Expand description

A reference to a position in a file.

Things to note:

  • This combines the previous functionality of FilePositionMarker and EnrichedFilePositionMarker. Additionally it contains a reference to the original templated file.
  • It no longer explicitly stores a line number or line position in the source or template. This is extrapolated from the templated file as required.
  • Positions in the source and template are with slices and therefore identify ranges.
  • Positions within the fixed file are identified with a line number and line position, which identify a point.
  • Arithmetic comparisons are on the location in the fixed file.

Fields§

§source_slice: Range<usize>§templated_slice: Range<usize>§templated_file: TemplatedFile§working_line_no: usize§working_line_pos: usize

Implementations§

source§

impl PositionMarker

source

pub fn new( source_slice: Range<usize>, templated_slice: Range<usize>, templated_file: TemplatedFile, working_line_no: Option<usize>, working_line_pos: Option<usize> ) -> Self

creates a PositionMarker

Unlike the Python version, post_init is embedded into the new function.

source

pub fn line_no(&self) -> usize

source

pub fn line_pos(&self) -> usize

source

pub fn from_child_markers(markers: Vec<PositionMarker>) -> PositionMarker

source

pub fn source_position(&self) -> (usize, usize)

Return the line and position of this marker in the source.

source

pub fn templated_position(&self) -> (usize, usize)

Return the line and position of this marker in the source.

source

pub fn working_loc_after(&self, raw: &str) -> (usize, usize)

source

pub fn infer_next_position( raw: &str, line_no: usize, line_pos: usize ) -> (usize, usize)

Using the raw string provided to infer the position of the next. Line position in 1-indexed.

source

pub fn working_loc(&self) -> (usize, usize)

Location tuple for the working position.

source

pub fn from_point( source_point: usize, templated_point: usize, templated_file: TemplatedFile, working_line_no: Option<usize>, working_line_pos: Option<usize> ) -> Self

Convenience method for creating point markers.

source

pub fn start_point_marker(&self) -> PositionMarker

Get a point marker from the start.

source

pub fn is_literal(&self) -> bool

Infer literalness from context.

is_literal should return True if a fix can be applied across this area in the templated file while being confident that the fix is still appropriate in the source file. This obviously applies to any slices which are the same in the source and the templated files. Slices which are zero-length in the source are also “literal” because they can’t be “broken” by any fixes, because they don’t exist in the source. This includes meta segments and any segments added during the fixing process.

This value is used for: - Ignoring linting errors in templated sections. - Whether iter_patches can return without recursing. - Whether certain rules (such as JJ01) are triggered.

source

pub fn from_points( start_point_marker: &PositionMarker, end_point_marker: &PositionMarker ) -> PositionMarker

Trait Implementations§

source§

impl Clone for PositionMarker

source§

fn clone(&self) -> PositionMarker

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for PositionMarker

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for PositionMarker

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Hash for PositionMarker

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for PositionMarker

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for PositionMarker

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for PositionMarker

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> Config for T

source§

fn config(self, f: impl FnOnce(&mut Self)) -> Self

source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

source§

impl<T> DynEq for T
where T: Any + PartialEq,

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

fn dyn_eq(&self, other: &(dyn DynEq + 'static)) -> bool

source§

impl<T> DynHash for T
where T: Hash + ?Sized,

source§

fn dyn_hash(&self, state: &mut dyn Hasher)

source§

impl<T> DynOrd for T
where T: Any + PartialOrd,

source§

fn dyn_ord(&self, other: &(dyn DynOrd + 'static)) -> Option<Ordering>

source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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.
source§

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

§

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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Any for T
where T: Any,

source§

impl<T> CloneAny for T
where T: Any + Clone,