pub struct Pos<T, FILE = NoFile> { /* private fields */ }Expand description
A positioned object, functionally equivalent to a struct containing an object of type T (the
wrapped object) and its position as a Position<FILE> object.
A parser uses characters inside a text file to create more complex objects. When the parsing fails due to a syntax error you must inform the user about it, in particular you need to tell the user where is the error.
This type associates to a type T (usually a token) a Position that allows the user to locate it inside
the file
Implementations§
Source§impl<T, F> Pos<T, F>
impl<T, F> Pos<T, F>
Sourcepub const fn new_pos(el: T, file: F, line: u32, column: u32) -> Self
pub const fn new_pos(el: T, file: F, line: u32, column: u32) -> Self
Creates a new positioned object.
Sourcepub fn take_all(self) -> (T, Position<F>)
pub fn take_all(self) -> (T, Position<F>)
Consumes the objects and returns both the wrapped element and the position
Sourcepub fn test_pos<TF: FnOnce(&T, &Position<F>) -> bool>(&self, f: TF) -> bool
pub fn test_pos<TF: FnOnce(&T, &Position<F>) -> bool>(&self, f: TF) -> bool
Tests both the wrapped object and its position
Source§impl<T, E, F> Pos<Result<T, E>, F>
impl<T, E, F> Pos<Result<T, E>, F>
Sourcepub fn from_output(out: Pos<T, F>) -> Self
pub fn from_output(out: Pos<T, F>) -> Self
Build result from output
Sourcepub fn from_output_pos(out: T, pos: Position<F>) -> Self
pub fn from_output_pos(out: T, pos: Position<F>) -> Self
Build result from output and position
Sourcepub fn from_residual(out: Pos<Result<Infallible, E>, F>) -> Self
pub fn from_residual(out: Pos<Result<Infallible, E>, F>) -> Self
Build result from residual
Sourcepub fn from_residual_pos(out: Result<Infallible, E>, pos: Position<F>) -> Self
pub fn from_residual_pos(out: Result<Infallible, E>, pos: Position<F>) -> Self
Build result from residual and position
Sourcepub const fn from_err_pos(out: E, pos: Position<F>) -> Self
pub const fn from_err_pos(out: E, pos: Position<F>) -> Self
Build result from error and position
Sourcepub fn branch(self) -> ControlFlow<Pos<Result<Infallible, E>, F>, Pos<T, F>>
pub fn branch(self) -> ControlFlow<Pos<Result<Infallible, E>, F>, Pos<T, F>>
Branch
Sourcepub fn throw(self) -> Result<Pos<T, F>, Pos<E, F>>
pub fn throw(self) -> Result<Pos<T, F>, Pos<E, F>>
Converts a Pos<Result<T, E>, F> into Result<Pos<T, F>, Pos<E, F>> that can be used with
the ? operator
Source§impl<T, F> Pos<Option<T>, F>
impl<T, F> Pos<Option<T>, F>
Source§impl<B, C, F> Pos<ControlFlow<B, C>, F>
impl<B, C, F> Pos<ControlFlow<B, C>, F>
Sourcepub fn try_break(self) -> ControlFlow<Pos<B, F>, C>
pub fn try_break(self) -> ControlFlow<Pos<B, F>, C>
Converts a Pos<ControlFlow<B, C>, F> into a ControlFlow<Pos<B, F>, C> by moving the
resulting Position to the break case