Skip to content

Commit

Permalink
Add more documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
doonv committed Dec 30, 2023
1 parent 76c67ff commit d77c242
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 43 deletions.
37 changes: 0 additions & 37 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ edition = "2021"
[features]
default = ["builtin-parser"]

builtin-parser = ["dep:logos", "dep:kinded"]
builtin-parser = ["dep:logos"]

[dependencies]
bevy = "0.12.1"
Expand All @@ -18,9 +18,8 @@ tracing-log = "0.2.0"
tracing-subscriber = "0.3.18"
web-time = "0.2.4"

# built-in parser
# builtin-parser feature
logos = { version = "0.13.0", optional = true }
kinded = { version = "0.3.0", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
android_log-sys = "0.3.0"
Expand Down
9 changes: 6 additions & 3 deletions src/builtin_parser/number.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![allow(non_camel_case_types)]

use std::fmt::Display;
use std::ops::*;

Expand All @@ -8,12 +6,13 @@ use logos::Span;

use super::{RunError, SpanExtension, Spanned};

/// An enum for containing any type of number.
/// An enum that contains any type of number.
///
/// The [`Integer`](Number::Integer) and [`Float`](Number::Float) types
/// are generic types that then get downcasted when they first interact
/// with a concrete type. (i.e. calling a function, etc)
#[derive(Debug, Clone, Copy)]
#[allow(missing_docs, non_camel_case_types)]
pub enum Number {
/// Generic integer that can get downcasted.
Integer(i128),
Expand All @@ -33,6 +32,7 @@ pub enum Number {
}

impl Number {
/// Converts this into a [`Box<dyn Reflect>`](Reflect).
pub fn reflect(self) -> Box<dyn Reflect> {
match self {
Number::u8(number) => Box::new(number),
Expand All @@ -50,6 +50,7 @@ impl Number {
}
}

/// Returns a [`&'static str`](str) represents the kind of the number.
pub fn kind(&self) -> &'static str {
match self {
Number::Float(_) => "(float)",
Expand Down Expand Up @@ -90,6 +91,7 @@ impl Display for Number {
macro_rules! impl_op {
($fn:ident, $op:tt) => {
impl Number {
#[doc = concat!("Performs the `", stringify!($op), "` calculation.")]
pub fn $fn(left: Number, right: Number, span: Span) -> Result<Number, RunError> {
match (left, right) {
(Number::u8(left), Number::u8(right)) => Ok(Number::u8(left $op right)),
Expand Down Expand Up @@ -162,6 +164,7 @@ impl_op_spanned!(Mul, mul);
impl_op_spanned!(Rem, rem);

impl Number {
/// Performs the unary `-` operation.
pub fn neg(self, span: Span) -> Result<Number, RunError> {
match self {
Number::u8(_) => Err(RunError::CannotNegateUnsignedInteger(Spanned {
Expand Down

0 comments on commit d77c242

Please sign in to comment.