From 32bde2f749340a5b1d965fd9b6946c83ca37a480 Mon Sep 17 00:00:00 2001 From: John Date: Mon, 23 Oct 2023 23:43:11 -0500 Subject: [PATCH] Minor documentation fixes --- libconlang/src/ast.rs | 8 +++++--- libconlang/src/parser.rs | 17 +++++++++-------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/libconlang/src/ast.rs b/libconlang/src/ast.rs index 0921c25..4a2f453 100644 --- a/libconlang/src/ast.rs +++ b/libconlang/src/ast.rs @@ -24,7 +24,8 @@ pub mod preamble { }; } -mod visitor { +pub mod visitor { + //! A [`Visitor`] visits every kind of node in the [Abstract Syntax Tree](super). Nodes, conversely are [`Walkers`](Walk) for Visitors which return a [`Result<(), E>`](Result) use super::{ expression::{ control::*, @@ -34,12 +35,12 @@ mod visitor { literal::*, *, }; - /// [Walk] traverses the AST, calling [`Visitor::visit_*()`](Visitor) on all the nodes + /// A [Walker](Walk) is a node in the AST, and calls [`Visitor::visit_*()`](Visitor) on all its children pub trait Walk + ?Sized, R> { /// Traverses the children of this node in order, calling the appropriate [Visitor] function fn walk(&self, visitor: &mut T) -> R; } - pub mod walker { + mod walker { use super::*; macro leaf($($T:ty),*$(,)?) {$( impl> + ?Sized, E> Walk> for $T { @@ -174,6 +175,7 @@ mod visitor { } } + /// A Visitor traverses every kind of node in the [Abstract Syntax Tree](super) pub trait Visitor { /// Visit the start of an AST fn visit(&mut self, start: &Start) -> R { diff --git a/libconlang/src/parser.rs b/libconlang/src/parser.rs index 8038e14..470a29f 100644 --- a/libconlang/src/parser.rs +++ b/libconlang/src/parser.rs @@ -76,9 +76,10 @@ pub mod error { } macro error_impl($($fn:ident$(($($p:ident: $t:ty),*))?: $reason:expr),*$(,)?) {$( - /// Creates an [Error] with this [Reason]: - #[doc = concat!("[`", stringify!($reason), "`]")] - pub fn $fn($($($p : $t),*)?) -> Self { + /// Creates an [Error] with this [Reason]: + #[doc = concat!("[`", stringify!($reason), "`]")] + #[allow(dead_code)] + pub(crate) fn $fn($($($p : $t),*)?) -> Self { Self { reason: $reason$(($($p)*))?, start: None } } )*} @@ -160,7 +161,7 @@ impl Parser { } /// Consume the current token #[inline] - pub fn consume(&mut self) -> &mut Self { + fn consume(&mut self) -> &mut Self { self.curr += 1; self.consume_comments(); self @@ -172,22 +173,22 @@ impl Parser { .ok_or(Error::end_of_file().maybe_token(self.tokens.last().cloned())) } /// Records the current position on the panic stack - pub fn mark(&mut self) -> &mut Self { + fn mark(&mut self) -> &mut Self { self.panic_stack.push(self.curr); self } /// Erases a recorded position from the panic stack - pub fn unmark(&mut self) -> &mut Self { + fn unmark(&mut self) -> &mut Self { self.panic_stack.pop(); self } /// Unwinds the panic stack one step - pub fn unwind(&mut self) -> PResult<&mut Self> { + fn unwind(&mut self) -> PResult<&mut Self> { let v = self.panic_stack.pop().ok_or(Error::panic_underflow())?; self.curr = v; Ok(self) } - pub fn advance_until(&mut self, t: Type) -> PResult<&mut Self> { + fn advance_until(&mut self, t: Type) -> PResult<&mut Self> { while self.matches(t).is_err() { self.check_eof() .map_err(|e| e.reason(Expected(t)))?