token: docs

pat: Token::kind
This commit is contained in:
2025-10-28 23:02:33 -04:00
parent d5e25a15dc
commit 9a0d1232a6
2 changed files with 7 additions and 2 deletions

View File

@@ -82,7 +82,7 @@ impl<'t> Parse<'t> for Pat {
_ => {
let mut path: Path = p.parse(())?;
// TODO: make these postfix.
match p.peek().map(|t| t.kind) {
match p.peek().map(Token::kind) {
Ok(TKind::LParen) => Pat::NamedTuple(path, p.parse(Prec::Typed)?),
Ok(TKind::LCurly) if level <= Prec::Tuple.next() => Pat::NamedStruct(
path,
@@ -139,7 +139,7 @@ impl<'t> Parse<'t> for Pat {
PatOp::Fn => Pat::Op(PatOp::Fn, vec![head, p.consume().parse(Prec::Fn.next())?]),
op @ (PatOp::RangeEx | PatOp::RangeIn) => Pat::Op(
op,
match p.consume().peek().map(|t| t.kind) {
match p.consume().peek().map(Token::kind) {
Ok(TKind::Integer | TKind::Character | TKind::Identifier) => {
vec![head, p.parse(prec.next())?]
}

View File

@@ -2,6 +2,7 @@
use crate::span::Span;
/// A unit of lexical information produced by the [Lexer](crate::lexer::Lexer)
#[derive(Clone, Debug)]
pub struct Token {
pub lexeme: Lexeme,
@@ -10,11 +11,14 @@ pub struct Token {
}
impl Token {
/// Extracts the `kind` field of this Token
pub const fn kind(&self) -> TKind {
self.kind
}
}
/// The (possibly pre-processed) lexical information, in the form of a
/// [String], [u128], or [char]
#[derive(Clone, Debug)]
pub enum Lexeme {
String(String),
@@ -59,6 +63,7 @@ impl std::fmt::Display for Lexeme {
}
}
/// The lexical classification of a [Token].
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TKind {
Comment, // Line or block comment