From 9a0d1232a6e3c8a711c6cc86eda44f58de388179 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 28 Oct 2025 23:02:33 -0400 Subject: [PATCH] token: docs pat: Token::kind --- src/parser/pat.rs | 4 ++-- src/token.rs | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/parser/pat.rs b/src/parser/pat.rs index 2b3d5f6..1127c53 100644 --- a/src/parser/pat.rs +++ b/src/parser/pat.rs @@ -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())?] } diff --git a/src/token.rs b/src/token.rs index bb0de9f..2364832 100644 --- a/src/token.rs +++ b/src/token.rs @@ -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