Write docs

This commit is contained in:
Jeff 2024-08-08 21:59:09 -04:00
parent 77134e5292
commit cccbe7a325
9 changed files with 28 additions and 21 deletions

View File

@ -1,3 +1,4 @@
//! In-memory representation of a Dust program.
use std::{ use std::{
collections::{HashMap, VecDeque}, collections::{HashMap, VecDeque},
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
@ -7,6 +8,7 @@ use serde::{Deserialize, Serialize};
use crate::{BuiltInFunction, Identifier, Span, Type, Value}; use crate::{BuiltInFunction, Identifier, Span, Type, Value};
/// In-memory representation of a Dust program.
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct AbstractSyntaxTree { pub struct AbstractSyntaxTree {
pub nodes: VecDeque<Node>, pub nodes: VecDeque<Node>,

View File

@ -1,3 +1,4 @@
//! Integrated functions that can be called from Dust code.
use std::{ use std::{
error::Error, error::Error,
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
@ -8,6 +9,7 @@ use serde::{Deserialize, Serialize};
use crate::{Type, Value}; use crate::{Type, Value};
/// Integrated function that can be called from Dust code.
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)] #[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum BuiltInFunction { pub enum BuiltInFunction {
// Integer and float tools // Integer and float tools

View File

@ -1,8 +1,11 @@
//! Top-level error handling for the Dust language.
use annotate_snippets::{Level, Renderer, Snippet}; use annotate_snippets::{Level, Renderer, Snippet};
use std::{error::Error, fmt::Display}; use std::{error::Error, fmt::Display};
use crate::{AnalyzerError, VmError}; use crate::{AnalyzerError, VmError};
/// An error that occurred during the execution of the Dust language and its
/// corresponding source code.
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub struct DustError<'src> { pub struct DustError<'src> {
vm_error: VmError, vm_error: VmError,
@ -43,11 +46,9 @@ impl<'src> DustError<'src> {
VmError::ExpectedValue { position } => position, VmError::ExpectedValue { position } => position,
}; };
let label = self.vm_error.to_string(); let label = self.vm_error.to_string();
let message = Level::Error.title(title).snippet( let message = Level::Error.title(title).snippet(
Snippet::source(self.source).annotation(Level::Info.span(span.0..span.1).label(&label)), Snippet::source(self.source).annotation(Level::Info.span(span.0..span.1).label(&label)),
); );
let renderer = Renderer::styled(); let renderer = Renderer::styled();
format!("{}", renderer.render(message)) format!("{}", renderer.render(message))

View File

@ -1,3 +1,4 @@
//! Key used to identify a value or type.
use std::{ use std::{
collections::HashSet, collections::HashSet,
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},
@ -13,6 +14,7 @@ fn identifier_cache<'a>() -> &'a RwLock<HashSet<Identifier>> {
IDENTIFIER_CACHE.get_or_init(|| RwLock::new(HashSet::new())) IDENTIFIER_CACHE.get_or_init(|| RwLock::new(HashSet::new()))
} }
/// Key used to identify a value or type.
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord, Hash)]
pub struct Identifier(Arc<String>); pub struct Identifier(Arc<String>);

View File

@ -1,8 +1,8 @@
/// Parsing tools. //! Parsing tools.
/// //!
/// This module provides two parsing options: //! This module provides two parsing options:
/// - `parse` convenience function //! - `parse` convenience function
/// - `Parser` struct, which parses the input a statement at a time //! - `Parser` struct, which parses the input a statement at a time
use std::{ use std::{
collections::VecDeque, collections::VecDeque,
error::Error, error::Error,

View File

@ -1,3 +1,4 @@
//! Token and TokenOwned types.
use std::fmt::{self, Display, Formatter}; use std::fmt::{self, Display, Formatter};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};

View File

@ -1,16 +1,14 @@
/** /// Description of a kind of value.
Description of a kind of value. ///
/// Most types are concrete and specific, the exceptions are the Generic and Any types.
Most types are concrete and specific, the exceptions are the Generic and Any types. ///
/// Generic types are temporary placeholders that describe a type that will be defined later. The
Generic types are temporary placeholders that describe a type that will be defined later. The /// interpreter should use the analysis phase to enforce that all Generic types have a concrete
interpreter should use the validation phase to enforce that all Generic types have a concrete /// type assigned to them before the program is run.
type assigned to them before the program is run. ///
/// The Any type is used in cases where a value's type does not matter. For example, the standard
The Any type is used in cases where a value's type does not matter. For example, the standard /// library's "length" function does not care about the type of item in the list, only the list
library's "length" function does not care about the type of item in the list, only the list /// itself. So the input is defined as `[any]`, i.e. `Type::ListOf(Box::new(Type::Any))`.
itself. So the input is defined as `[any]`, i.e. `Type::ListOf(Box::new(Type::Any))`.
**/
use std::{ use std::{
collections::BTreeMap, collections::BTreeMap,
fmt::{self, Display, Formatter}, fmt::{self, Display, Formatter},

View File

@ -1,4 +1,4 @@
/// Dust value representation //! Dust value representation
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
collections::{BTreeMap, HashMap}, collections::{BTreeMap, HashMap},

View File

@ -1,3 +1,4 @@
//! Virtual machine for running the abstract syntax tree.
use std::{ use std::{
collections::HashMap, collections::HashMap,
error::Error, error::Error,