Minor documentation fixes
This commit is contained in:
parent
0e1beca43d
commit
32bde2f749
@ -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::{
|
use super::{
|
||||||
expression::{
|
expression::{
|
||||||
control::*,
|
control::*,
|
||||||
@ -34,12 +35,12 @@ mod visitor {
|
|||||||
literal::*,
|
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<T: Visitor<R> + ?Sized, R> {
|
pub trait Walk<T: Visitor<R> + ?Sized, R> {
|
||||||
/// Traverses the children of this node in order, calling the appropriate [Visitor] function
|
/// Traverses the children of this node in order, calling the appropriate [Visitor] function
|
||||||
fn walk(&self, visitor: &mut T) -> R;
|
fn walk(&self, visitor: &mut T) -> R;
|
||||||
}
|
}
|
||||||
pub mod walker {
|
mod walker {
|
||||||
use super::*;
|
use super::*;
|
||||||
macro leaf($($T:ty),*$(,)?) {$(
|
macro leaf($($T:ty),*$(,)?) {$(
|
||||||
impl<T: Visitor<Result<(), E>> + ?Sized, E> Walk<T, Result<(), E>> for $T {
|
impl<T: Visitor<Result<(), E>> + ?Sized, E> Walk<T, Result<(), E>> for $T {
|
||||||
@ -174,6 +175,7 @@ mod visitor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A Visitor traverses every kind of node in the [Abstract Syntax Tree](super)
|
||||||
pub trait Visitor<R> {
|
pub trait Visitor<R> {
|
||||||
/// Visit the start of an AST
|
/// Visit the start of an AST
|
||||||
fn visit(&mut self, start: &Start) -> R {
|
fn visit(&mut self, start: &Start) -> R {
|
||||||
|
@ -78,7 +78,8 @@ pub mod error {
|
|||||||
macro error_impl($($fn:ident$(($($p:ident: $t:ty),*))?: $reason:expr),*$(,)?) {$(
|
macro error_impl($($fn:ident$(($($p:ident: $t:ty),*))?: $reason:expr),*$(,)?) {$(
|
||||||
/// Creates an [Error] with this [Reason]:
|
/// Creates an [Error] with this [Reason]:
|
||||||
#[doc = concat!("[`", stringify!($reason), "`]")]
|
#[doc = concat!("[`", stringify!($reason), "`]")]
|
||||||
pub fn $fn($($($p : $t),*)?) -> Self {
|
#[allow(dead_code)]
|
||||||
|
pub(crate) fn $fn($($($p : $t),*)?) -> Self {
|
||||||
Self { reason: $reason$(($($p)*))?, start: None }
|
Self { reason: $reason$(($($p)*))?, start: None }
|
||||||
}
|
}
|
||||||
)*}
|
)*}
|
||||||
@ -160,7 +161,7 @@ impl Parser {
|
|||||||
}
|
}
|
||||||
/// Consume the current token
|
/// Consume the current token
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn consume(&mut self) -> &mut Self {
|
fn consume(&mut self) -> &mut Self {
|
||||||
self.curr += 1;
|
self.curr += 1;
|
||||||
self.consume_comments();
|
self.consume_comments();
|
||||||
self
|
self
|
||||||
@ -172,22 +173,22 @@ impl Parser {
|
|||||||
.ok_or(Error::end_of_file().maybe_token(self.tokens.last().cloned()))
|
.ok_or(Error::end_of_file().maybe_token(self.tokens.last().cloned()))
|
||||||
}
|
}
|
||||||
/// Records the current position on the panic stack
|
/// 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.panic_stack.push(self.curr);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
/// Erases a recorded position from the panic stack
|
/// 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.panic_stack.pop();
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
/// Unwinds the panic stack one step
|
/// 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())?;
|
let v = self.panic_stack.pop().ok_or(Error::panic_underflow())?;
|
||||||
self.curr = v;
|
self.curr = v;
|
||||||
Ok(self)
|
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() {
|
while self.matches(t).is_err() {
|
||||||
self.check_eof()
|
self.check_eof()
|
||||||
.map_err(|e| e.reason(Expected(t)))?
|
.map_err(|e| e.reason(Expected(t)))?
|
||||||
|
Loading…
Reference in New Issue
Block a user