pub struct Token(pub Loc<Result<Box<dyn Tree>, String>>);Expand description
Represents a parse Tree or a parse error, with a Location.
- Token(Loc(Ok(t), location)) represents a parse-tree
t.tcan beEndOfFileto represent the end of the source code. In this case, theLocationis spurious. - Token(Loc(Err(e), location)) represents an error message
e.ecan be the empty string to mark the end of incomplete source code. In this case, theLocationis spurious.
Tuple Fields§
§0: Loc<Result<Box<dyn Tree>, String>>Implementations§
Source§impl Token
impl Token
Sourcepub fn new(tree: Box<dyn Tree>, location: impl Into<Location>) -> Self
pub fn new(tree: Box<dyn Tree>, location: impl Into<Location>) -> Self
Constructs a Self from a Tree and its Location.
Sourcepub fn new_err(
message: impl Into<String>,
location: impl Into<Location>,
) -> Self
pub fn new_err( message: impl Into<String>, location: impl Into<Location>, ) -> Self
Constructs a Self from an error message and its Location.
Sourcepub fn end_of_file() -> Self
pub fn end_of_file() -> Self
Returns an EndOfFile, to indicate the end of the source code.
Sourcepub fn incomplete() -> Self
pub fn incomplete() -> Self
Returns an empty error message, to indicate incomplete source code.
Sourcepub fn is_incomplete(&self) -> bool
pub fn is_incomplete(&self) -> bool
Tests whether self marks the end of incomplete source code.
Sourcepub fn unwrap<T: Tree>(self) -> T
pub fn unwrap<T: Tree>(self) -> T
Discard the Location, panic on Err, and panic if the payload is
not of type T.
This is useful in test code.
Sourcepub fn unwrap_err(self) -> String
pub fn unwrap_err(self) -> String
Discard the Location, panic on Ok, return the error message.
This is useful in test code.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Token
impl !RefUnwindSafe for Token
impl !Send for Token
impl !Sync for Token
impl Unpin for Token
impl !UnwindSafe for Token
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
Mutably borrows from an owned value. Read more