Skip to content

Commit

Permalink
Merge pull request #1 from FL03/v0.0.1
Browse files Browse the repository at this point in the history
V0.0.1
  • Loading branch information
FL03 authored Jul 23, 2024
2 parents d9f1206 + 430ce6e commit f0ec785
Show file tree
Hide file tree
Showing 35 changed files with 1,214 additions and 729 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ keywords = [ ]
license = "Apache-2.0"
readme = "README.md"
repository = "https://github.com/FL03/rstm.git"
version = "0.0.0"
version = "0.0.1"

[profile.dev]
opt-level = 0
Expand Down
42 changes: 29 additions & 13 deletions rstm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,67 @@ repository.workspace = true
version.workspace = true

[features]
default = [
"std",
]
default = []

full = [
"default",
"serde",
"tracing",
]

# [FF] Dependencies
alloc = [
"serde?/alloc",
]
# alloc = [
# "serde?/alloc",
# ]

serde = [
"dep:serde",
]

# ********* [FF] Environments *********
std = [
"alloc",
"serde?/std",
"strum/std",
tracing = [
"dep:tracing",
]

# ********* [FF] Environments *********
# std = [
# "alloc",
# "serde?/std",
# "strum/std",
# ]

[lib]
bench = true
crate-type = ["cdylib", "rlib"]
doctest = false
test = true

[[example]]
name = "basic"
required-features = ["tracing"]

[dependencies]
thiserror = "1"

[dev-dependencies]
lazy_static = "1"
tracing-subscriber = { features = [], version = "0.3" }

[dependencies.serde]
default-features = false
# default-features = false
features = ["derive"]
optional = true
version = "1"

[dependencies.strum]
default-features = false
# default-features = false
features = ["derive"]
version = "0.26"

[dependencies.tracing]
features = []
optional = true
version = "0.1"

[package.metadata.docs.rs]
all-features = true
rustc-args = ["--cfg", "docsrs"]
28 changes: 28 additions & 0 deletions rstm/examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
Appellation: default <example>
Contrib: FL03 <jo3mccain@icloud.com>
*/
extern crate rstm;

use rstm::prelude::{State, Tape, TM};
use rstm::rule;
use rstm::state::binary::BinaryStates::*;

// use Direction::Right;

fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt().init();
let tape = Tape::from_str("10111000101001101011010010");
let initial_state = State(Invalid);

let rules = vec![
rule![(State(Invalid), '0') -> Right(State(Invalid), '1',)],
rule![(State(Invalid), '1') -> Right(State(Valid), '0',)],
rule![(State(Valid), '0') -> Right(State(Valid), '1',)],
rule![(State(Valid), '1') -> Right(State(Valid), '0',)],
];

let tm = TM::new(initial_state, rules, tape);
tm.run()?;
Ok(())
}
26 changes: 9 additions & 17 deletions rstm/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,42 @@
Appellation: error <module>
Contrib: FL03 <jo3mccain@icloud.com>
*/
use crate::state::State;

#[derive(
Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, strum::VariantNames, thiserror::Error,
)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
pub enum FsmError<T = String> {
pub enum FsmError {
#[error("[IndexError] Out of Bounds: {0}")]
IndexOutOfBounds(String),
#[error("[StateError] Invalid State: {0}")]
InvalidState(String),
#[error("[StateError] State not found: {current_state:?} with symbol: {read_symbol}")]
StateNotFound {
current_state: State<T>,
read_symbol: char,
},

#[error("[StateError] State Not Found: {0}")]
StateNotFound(String),
#[error("Transformation error: {0}")]
TransformationError(String),
#[error("Unknown error: {0}")]
Unknown(String),
}

impl<T> FsmError<T> {
impl FsmError {
pub fn index_out_of_bounds(err: impl ToString) -> Self {
FsmError::IndexOutOfBounds(err.to_string())
}

pub fn invalid_state(err: &str) -> Self {
pub fn invalid_state(err: impl ToString) -> Self {
FsmError::InvalidState(err.to_string())
}

pub fn state_not_found(state: State<T>, char: char) -> Self {
FsmError::StateNotFound {
current_state: state,
read_symbol: char,
}
pub fn state_not_found(err: impl ToString) -> Self {
FsmError::StateNotFound(err.to_string())
}

pub fn transformation_error(message: &str) -> Self {
pub fn transformation_error(message: impl ToString) -> Self {
FsmError::TransformationError(message.to_string())
}

pub fn unknown(message: &str) -> Self {
pub fn unknown(message: impl ToString) -> Self {
FsmError::Unknown(message.to_string())
}
}
12 changes: 8 additions & 4 deletions rstm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
*/
//! # rstm
//!
//!
// #![cfg_attr(not(feature = "std"), no_std)]
// #[cfg(feature = "alloc")]
// extern crate alloc;

#[doc(inline)]
pub use self::{error::FsmError, traits::prelude::*, types::prelude::*};
pub use self::{error::FsmError, state::State, traits::prelude::*, turing::TM, types::prelude::*};

#[macro_use]
pub(crate) mod macros;
#[macro_use]
pub(crate) mod seal;

pub mod error;
pub mod programs;
pub mod rules;
pub mod state;
pub mod traits;
pub mod turing;
pub mod types;

pub mod prelude {
pub use crate::error::FsmError;
pub use crate::programs::prelude::*;
pub use crate::rules::prelude::*;
pub use crate::state::prelude::*;
pub use crate::traits::prelude::*;
pub use crate::turing::prelude::*;
Expand Down
19 changes: 19 additions & 0 deletions rstm/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,22 @@
Contrib: FL03 <jo3mccain@icloud.com>
*/

#[macro_export]
macro_rules! rule {
[($state:expr, $symbol:literal $(,)?) -> $direction:ident($next:expr, $write:literal $(,)?) $(,)?] => {
$crate::rules::Instruction::new()
.state($state)
.symbol($symbol)
.write_symbol($write)
.direction($crate::Direction::$direction)
.next_state($next)
.build()
};
}

#[macro_export]
macro_rules! ruleset {
($($($rule:tt)*);* $(,)?) => {
vec![$(rule!($($rule)*)),*]
};
}
109 changes: 0 additions & 109 deletions rstm/src/programs/instruction.rs

This file was deleted.

Loading

0 comments on commit f0ec785

Please sign in to comment.