More documentation
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
mod macros;
|
||||
#[cfg(test)]
|
||||
mod test;
|
||||
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
#[macro_export]
|
||||
macro_rules! documented {
|
||||
// -------------------------------------------------------------------------
|
||||
// Internal Helper: Filter doc comments
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
// Case 1: Doc comment. Return Some("string").
|
||||
// We match the specific structure of a doc attribute.
|
||||
(@doc_filter #[doc = $doc:expr]) => {
|
||||
Some($doc)
|
||||
};
|
||||
|
||||
// Case 2: Other attributes (derives, etc.). Return None.
|
||||
// We catch any other token sequence inside the brackets.
|
||||
(@doc_filter #[$($attr:tt)*]) => {
|
||||
None
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Internal Helper: Match patterns for `match self`
|
||||
// -------------------------------------------------------------------------
|
||||
(@arm $name:ident $variant:ident) => {
|
||||
$name::$variant
|
||||
};
|
||||
(@arm $name:ident $variant:ident ( $($tuple:tt)* )) => {
|
||||
$name::$variant(..)
|
||||
};
|
||||
(@arm $name:ident $variant:ident { $($structure:tt)* }) => {
|
||||
$name::$variant{..}
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Main Macro Entry Point
|
||||
// -------------------------------------------------------------------------
|
||||
(
|
||||
$(#[$enum_attr:meta])* $vis:vis enum $name:ident {
|
||||
$(
|
||||
// Capture attributes as a sequence of token trees inside brackets
|
||||
// to avoid "local ambiguity" and handle multi-token attributes (like doc="...").
|
||||
$(#[ $($variant_attr:tt)* ])*
|
||||
$variant:ident
|
||||
$( ($($tuple:tt)*) )?
|
||||
$( {$($structure:tt)*} )?
|
||||
),* $(,)?
|
||||
}
|
||||
) => {
|
||||
// 1. Generate the actual Enum definition
|
||||
$(#[$enum_attr])*
|
||||
$vis enum $name {
|
||||
$(
|
||||
$(#[ $($variant_attr)* ])*
|
||||
$variant
|
||||
$( ($($tuple)*) )?
|
||||
$( {$($structure)*} )?,
|
||||
)*
|
||||
}
|
||||
|
||||
// 2. Implement the Trait
|
||||
impl Documentation for $name {
|
||||
fn docs(&self) -> String {
|
||||
match self {
|
||||
$(
|
||||
documented!(@arm $name $variant $( ($($tuple)*) )? $( {$($structure)*} )? ) => {
|
||||
// Create a temporary array of Option<&str> for all attributes
|
||||
let doc_lines: &[Option<&str>] = &[
|
||||
$(
|
||||
documented!(@doc_filter #[ $($variant_attr)* ])
|
||||
),*
|
||||
];
|
||||
|
||||
// Filter out the Nones (non-doc attributes), join, and return
|
||||
doc_lines.iter()
|
||||
.filter_map(|&d| d)
|
||||
.collect::<Vec<_>>()
|
||||
.join("\n")
|
||||
.trim()
|
||||
.to_string()
|
||||
}
|
||||
)*
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::LiteralOrVariable;
|
||||
use crate::tree_node::{Expression, Literal, Spanned};
|
||||
use crate::{Documentation, documented};
|
||||
use helpers::prelude::*;
|
||||
|
||||
documented! {
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
@@ -48,7 +48,7 @@ documented! {
|
||||
/// `(number|var).cos();`
|
||||
Cos(LiteralOrVariable),
|
||||
/// Rounds a number down to the nearest whole number.
|
||||
/// ## In Game
|
||||
/// ## IC10
|
||||
/// `floor r? a(r?|num)`
|
||||
/// ## Slang
|
||||
/// `(number|var).floor();`
|
||||
@@ -131,30 +131,35 @@ documented! {
|
||||
#[derive(Debug, PartialEq, Eq)]
|
||||
pub enum System {
|
||||
/// Pauses execution for exactly 1 tick and then resumes.
|
||||
/// ## In Game
|
||||
/// yield
|
||||
/// ## IC10
|
||||
/// `yield`
|
||||
/// ## Slang
|
||||
/// `yield();`
|
||||
Yield,
|
||||
/// Represents a function that can be called to sleep for a certain amount of time.
|
||||
/// ## In Game
|
||||
/// ## IC10
|
||||
/// `sleep a(r?|num)`
|
||||
/// ## Slang
|
||||
/// `sleep(number|var);`
|
||||
Sleep(Box<Spanned<Expression>>),
|
||||
/// Gets the in-game hash for a specific prefab name.
|
||||
/// ## In Game
|
||||
/// ## IC10
|
||||
/// `HASH("prefabName")`
|
||||
/// ## Slang
|
||||
/// `HASH("prefabName");`
|
||||
Hash(Literal),
|
||||
/// Represents a function which loads a device variable into a register.
|
||||
/// ## In Game
|
||||
/// ## IC10
|
||||
/// `l r? d? var`
|
||||
/// ## Examples
|
||||
/// `l r0 d0 Setting`
|
||||
/// `l r1 d5 Pressure`
|
||||
/// ## Slang
|
||||
/// `loadFromDevice(deviceType, "LogicType");`
|
||||
LoadFromDevice(LiteralOrVariable, Literal),
|
||||
/// Function which gets a LogicType from all connected network devices that match
|
||||
/// the provided device hash and name, aggregating them via a batchMode
|
||||
/// ## In Game
|
||||
/// lbn r? deviceHash nameHash logicType batchMode
|
||||
/// ## Examples
|
||||
/// lbn r0 HASH("StructureWallLight") HASH("wallLight") On Minimum
|
||||
/// ## IC10
|
||||
/// `lbn r? deviceHash nameHash logicType batchMode`
|
||||
/// ## Slang
|
||||
/// `loadFromDeviceBatchedNamed(deviceHash, deviceName, "LogicType", "BatchMode");`
|
||||
LoadBatchNamed(
|
||||
LiteralOrVariable,
|
||||
Box<Spanned<Expression>>,
|
||||
@@ -163,30 +168,28 @@ documented! {
|
||||
),
|
||||
/// Loads a LogicType from all connected network devices, aggregating them via a
|
||||
/// batchMode
|
||||
/// ## In Game
|
||||
/// lb r? deviceHash logicType batchMode
|
||||
/// ## Examples
|
||||
/// lb r0 HASH("StructureWallLight") On Minimum
|
||||
/// ## IC10
|
||||
/// `lb r? deviceHash logicType batchMode`
|
||||
/// ## Slang
|
||||
/// `loadFromDeviceBatched(deviceHash, "Variable", "LogicType");`
|
||||
LoadBatch(LiteralOrVariable, Literal, Literal),
|
||||
/// Represents a function which stores a setting into a specific device.
|
||||
/// ## In Game
|
||||
/// ## IC10
|
||||
/// `s d? logicType r?`
|
||||
/// ## Example
|
||||
/// `s d0 Setting r0`
|
||||
/// ## Slang
|
||||
/// `setOnDevice(deviceType, "Variable", (number|var));`
|
||||
SetOnDevice(LiteralOrVariable, Literal, Box<Spanned<Expression>>),
|
||||
/// Represents a function which stores a setting to all devices that match
|
||||
/// the given deviceHash
|
||||
/// ## In Game
|
||||
/// ## IC10
|
||||
/// `sb deviceHash logicType r?`
|
||||
/// ## Example
|
||||
/// `sb HASH("Doors") Lock 1`
|
||||
SetOnDeviceBatched(LiteralOrVariable, Literal, Box<Spanned<Expression>>),
|
||||
/// Represents a function which stores a setting to all devices that match
|
||||
/// both the given deviceHash AND the given nameHash
|
||||
/// ## In Game
|
||||
/// ## IC10
|
||||
/// `sbn deviceHash nameHash logicType r?`
|
||||
/// ## Example
|
||||
/// `sbn HASH("Doors") HASH("Exterior") Lock 1`
|
||||
/// ## Slang
|
||||
/// `setOnDeviceBatchedNamed(deviceType, nameHash, "LogicType", (number|var))`
|
||||
SetOnDeviceBatchedNamed(
|
||||
LiteralOrVariable,
|
||||
LiteralOrVariable,
|
||||
@@ -226,6 +229,15 @@ pub enum SysCall {
|
||||
Math(Math),
|
||||
}
|
||||
|
||||
impl Documentation for SysCall {
|
||||
fn docs(&self) -> String {
|
||||
match self {
|
||||
Self::System(s) => s.docs(),
|
||||
Self::Math(m) => m.docs(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl std::fmt::Display for SysCall {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::Documentation;
|
||||
use crate::sys_call;
|
||||
use helpers::Documentation;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user