Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,11 @@
//! ```

use anyhow::{anyhow, Context, Result};
use indexmap::IndexMap;
pub use indexmap::IndexMap;
#[cfg(feature = "rhai")]
use rhai::{Engine, AST};
use rhai::Engine;
#[cfg(feature = "rhai")]
pub use rhai::AST;
use serde::Deserialize;
use std::{fs, path::Path};
use toml::{self};
Expand Down
2 changes: 1 addition & 1 deletion engine/preprocessor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ inhibit = []
serde = ["dep:serde", "keyboard-types/serde"]

[dependencies]
keyboard-types = { version = "0.8.3", default-features = false }
keyboard-types = { version = "0.8.3", features = ["webdriver"] }
afrim-memory = { version = "0.4.2", path = "../../memory" }
serde = { version = "1.0.228", features = ["derive"], optional = true }

Expand Down
46 changes: 21 additions & 25 deletions engine/preprocessor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,12 @@
//! # Example
//!
//! ```
//! use afrim_preprocessor::{utils, Command, Preprocessor};
//! use keyboard_types::{
//! webdriver::{self, Event},
//! };
//! use afrim_preprocessor::{utils::{self, webdriver}, Command, Preprocessor, Node};
//! use std::{collections::VecDeque, rc::Rc};
//!
//! // Prepares the memory.
//! let data = utils::load_data("cc ç");
//! let text_buffer = utils::build_map(data);
//! let text_buffer: Node = utils::build_map(data);
//! let memory = Rc::new(text_buffer);
//!
//! // Builds the preprocessor.
Expand All @@ -29,7 +26,7 @@
//! .for_each(|event| {
//! match event {
//! // Triggers the generated keyboard input event.
//! Event::Keyboard(event) => preprocessor.process(event),
//! webdriver::Event::Keyboard(event) => preprocessor.process(event),
//! _ => unimplemented!(),
//! };
//! });
Expand Down Expand Up @@ -69,11 +66,17 @@
mod message;

pub use crate::message::Command;
pub use afrim_memory::utils;
use afrim_memory::{Cursor, Node};
use afrim_memory::Cursor;
pub use afrim_memory::Node;
pub use keyboard_types::{Key, KeyState, KeyboardEvent, NamedKey};
use std::{collections::VecDeque, rc::Rc};

/// Utilities.
pub mod utils {
pub use afrim_memory::utils::{build_map, load_data};
pub use keyboard_types::webdriver;
}

/// The main structure of the preprocessor.
#[derive(Debug)]
pub struct Preprocessor {
Expand Down Expand Up @@ -297,8 +300,7 @@ impl Preprocessor {
/// # Example
///
/// ```
/// use afrim_preprocessor::{Command, Preprocessor, utils};
/// use keyboard_types::{Key::Character, KeyboardEvent};
/// use afrim_preprocessor::{Command, Preprocessor, utils, KeyboardEvent, Key::Character};
/// use std::{collections::VecDeque, rc::Rc};
///
/// // We prepare the memory.
Expand Down Expand Up @@ -377,8 +379,7 @@ impl Preprocessor {
/// # Example
///
/// ```
/// use afrim_preprocessor::{Command, Preprocessor, utils};
/// use keyboard_types::webdriver::{self, Event};
/// use afrim_preprocessor::{Command, Preprocessor, utils::{self, webdriver}};
/// use std::{collections::VecDeque, rc::Rc};
///
/// // We prepare the memory.
Expand All @@ -395,7 +396,7 @@ impl Preprocessor {
/// .for_each(|event| {
/// match event {
/// // Triggers the generated keyboard input event.
/// Event::Keyboard(event) => preprocessor.process(event),
/// webdriver::Event::Keyboard(event) => preprocessor.process(event),
/// _ => unimplemented!(),
/// };
/// });
Expand Down Expand Up @@ -470,12 +471,11 @@ impl Preprocessor {
#[cfg(test)]
mod tests {
use crate::message::Command;
use crate::utils;
use crate::Preprocessor;
use keyboard_types::{
webdriver::{self, Event},
Key::*,
NamedKey,
use crate::{
utils::{self, webdriver},
Key::{Character, Named},
KeyboardEvent, NamedKey, Node,
};
use std::collections::VecDeque;

Expand All @@ -488,7 +488,7 @@ mod tests {
let mut preprocessor = Preprocessor::new(Rc::new(memory), 8);
webdriver::send_keys("ccced").into_iter().for_each(|e| {
match e {
Event::Keyboard(e) => preprocessor.process(e),
webdriver::Event::Keyboard(e) => preprocessor.process(e),
_ => unimplemented!(),
};
});
Expand Down Expand Up @@ -541,9 +541,6 @@ mod tests {

#[test]
fn test_commit() {
use afrim_memory::Node;
use keyboard_types::KeyboardEvent;

let mut preprocessor = Preprocessor::new(Node::default().into(), 8);
preprocessor.process(KeyboardEvent {
key: Character("a".to_owned()),
Expand All @@ -570,7 +567,6 @@ mod tests {

#[test]
fn test_rollback() {
use keyboard_types::KeyboardEvent;
use std::rc::Rc;

let data = utils::load_data("ccced ç\ncc ç");
Expand All @@ -583,7 +579,7 @@ mod tests {

webdriver::send_keys("ccced").into_iter().for_each(|e| {
match e {
Event::Keyboard(e) => preprocessor.process(e),
webdriver::Event::Keyboard(e) => preprocessor.process(e),
_ => unimplemented!(),
};
});
Expand Down Expand Up @@ -632,7 +628,7 @@ mod tests {
\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}\u{E003}"
).into_iter().for_each(|e| {
match e {
Event::Keyboard(e) => preprocessor.process(e),
webdriver::Event::Keyboard(e) => preprocessor.process(e),
_ => unimplemented!(),
};
});
Expand Down
36 changes: 15 additions & 21 deletions engine/translator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
//! # Example
//!
//! ```
//! use afrim_translator::{Predicate, Translator};
//! use indexmap::IndexMap;
//! use afrim_translator::{Predicate, Translator, IndexMap};
//! #[cfg(feature = "rhai")]
//! use afrim_translator::AST;
//!
//! // Prepares the dictionary.
//! let mut dictionary = IndexMap::new();
Expand Down Expand Up @@ -55,8 +56,7 @@
//! # Example with the strsim feature
//!
//! ```
//! use afrim_translator::{Predicate, Translator};
//! use indexmap::IndexMap;
//! use afrim_translator::{Predicate, Translator, IndexMap};
//!
//! // Prepares the dictionary.
//! let mut dictionary = IndexMap::new();
Expand All @@ -83,9 +83,8 @@
//!
//! ```
//! #[cfg(feature = "rhai")]
//! use afrim_translator::Engine;
//! use afrim_translator::{Translator, Predicate};
//! use indexmap::IndexMap;
//! use afrim_translator::{AST, Engine};
//! use afrim_translator::{Predicate, Translator, IndexMap};
//!
//! // Prepares the dictionary.
//! let mut dictionary = IndexMap::new();
Expand All @@ -96,7 +95,7 @@
//! #[cfg(feature = "rhai")]
//! let engine = Engine::new();
//! #[cfg(feature = "rhai")]
//! let jump_translator = engine.compile(r#"
//! let jump_translator: AST = engine.compile(r#"
//! // The main script function.
//! fn translate(input) {
//! if input == "jump" {
Expand Down Expand Up @@ -140,11 +139,11 @@
//! );
//! ```

use indexmap::IndexMap;
pub use indexmap::IndexMap;
#[cfg(feature = "rhai")]
pub use rhai::Engine;
use rhai::{Array, Scope};
#[cfg(feature = "rhai")]
use rhai::{Array, Scope, AST};
pub use rhai::{Engine, AST};
use std::cmp::Ordering;
#[cfg(feature = "strsim")]
use strsim::{self};
Expand Down Expand Up @@ -180,8 +179,7 @@ impl Translator {
/// # Example
///
/// ```
/// use afrim_translator::Translator;
/// use indexmap::IndexMap;
/// use afrim_translator::{Translator, IndexMap};
///
/// let dictionary = IndexMap::new();
/// let translator = Translator::new(dictionary, false, 0.7);
Expand Down Expand Up @@ -211,8 +209,7 @@ impl Translator {
/// # Example
///
/// ```
/// use afrim_translator::{Engine, Predicate, Translator};
/// use indexmap::IndexMap;
/// use afrim_translator::{Engine, Predicate, Translator, IndexMap};
///
/// // We prepare the script.
/// let date_translator = r#"
Expand Down Expand Up @@ -280,8 +277,7 @@ impl Translator {
///
/// # Example
/// ```
/// use afrim_translator::{Engine, Predicate, Translator};
/// use indexmap::IndexMap;
/// use afrim_translator::{Engine, Predicate, Translator, IndexMap};
///
/// // We prepare the script.
/// let engine = Engine::new();
Expand Down Expand Up @@ -317,8 +313,7 @@ impl Translator {
/// # Example
///
/// ```
/// use indexmap::IndexMap;
/// use afrim_translator::{Predicate, Translator};
/// use afrim_translator::{IndexMap, Predicate, Translator};
///
/// // We prepares the dictionary.
/// let mut dictionary = IndexMap::new();
Expand Down Expand Up @@ -476,8 +471,7 @@ mod tests {
fn test_translate() {
#[cfg(feature = "rhai")]
use crate::Engine;
use crate::{Predicate, Translator};
use indexmap::IndexMap;
use crate::{IndexMap, Predicate, Translator};

// We build the translation
let mut dictionary = IndexMap::new();
Expand Down
Loading