-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
157 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,17 @@ | ||
[package] | ||
name = "rewrite" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
name = "rewrite" | ||
version.workspace = true | ||
authors.workspace = true | ||
license.workspace = true | ||
edition.workspace = true | ||
repository.workspace = true | ||
|
||
[features] | ||
default = ["std", "macros", "plugins"] | ||
std = [] | ||
macros = ["choco_macros", "plugins"] | ||
plugins = ["petgraph", "std"] | ||
|
||
[dependencies] | ||
choco_macros = { workspace = true, optional = true } | ||
petgraph = { workspace = true, optional = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
pub mod core; | ||
#![cfg_attr(not(feature = "std"), no_std)] | ||
|
||
pub mod core; | ||
pub mod plugins; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pub mod block; | ||
pub mod graph; | ||
pub mod logic; | ||
pub mod many_of; | ||
pub mod one_of; | ||
pub mod vars; |
Empty file.
Empty file.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use crate::core::{Event, EventFlow, PluginError, StrRange}; | ||
use core::any::TypeId; | ||
|
||
pub trait OneOf: Sized + 'static { | ||
fn one_of(param: &str) -> Option<Self>; | ||
|
||
fn prompt() -> &'static str; | ||
} | ||
|
||
pub struct Plugin<T: OneOf>(Option<T>); | ||
|
||
impl<T: OneOf> Plugin<T> { | ||
pub fn last(&self) -> Option<&T> { | ||
self.0.as_ref() | ||
} | ||
} | ||
|
||
impl<T: OneOf> crate::core::Plugin for Plugin<T> { | ||
fn take_signal<P: crate::core::Plugin>( | ||
signal: StrRange, | ||
mut flow: EventFlow<P>, | ||
) -> crate::core::PluginResult<Option<TypeId>> { | ||
if signal.substr() == T::prompt() { | ||
let err = || PluginError::new::<Self>(signal.range.clone()); | ||
let param = flow.next().ok_or_else(|| err().with_msg("no param"))?; | ||
let raw = match param { | ||
Event::Raw(raw) if raw.is_signal() => raw, | ||
_ => return Err(err().with_msg("param is not a signal")), | ||
}; | ||
let one_of = T::one_of(raw.as_of(flow.full_str()).substr()); | ||
let Some(self_) = flow.plugins.get_sub_mut::<Self>() else { | ||
return Err(err().with_msg("can't find `Self` in `plugins`")); | ||
}; | ||
self_.0 = one_of; | ||
Ok(Some(TypeId::of::<Self>())) | ||
} else { | ||
Ok(None) | ||
} | ||
} | ||
} |
Empty file.