pub struct Token {
pub kind: TokenKind,
pub text: Arc<str>,
pub start: usize,
pub end: usize,
}Expand description
Token produced by the lexer and consumed by the parser.
Stores the token kind, original source text, and byte span. The text is kept
in an Arc<str> so buffering and lookahead can clone tokens cheaply.
Fields§
§kind: TokenKindToken classification for parser decision making
text: Arc<str>Original source text for precise reconstruction
start: usizeStarting byte position for error reporting and location tracking
end: usizeEnding byte position for span calculation and navigation
Implementations§
Source§impl Token
impl Token
Sourcepub fn new(
kind: TokenKind,
text: impl Into<Arc<str>>,
start: usize,
end: usize,
) -> Token
pub fn new( kind: TokenKind, text: impl Into<Arc<str>>, start: usize, end: usize, ) -> Token
Create a new token with the given kind, source text, and byte span.
§Examples
use perl_token::{Token, TokenKind};
let tok = Token::new(TokenKind::Sub, "sub", 0, 3);
assert_eq!(tok.kind, TokenKind::Sub);
assert_eq!(&*tok.text, "sub");Trait Implementations§
impl StructuralPartialEq for Token
Auto Trait Implementations§
impl Freeze for Token
impl RefUnwindSafe for Token
impl Send for Token
impl Sync for Token
impl Unpin for Token
impl UnsafeUnpin 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