diff --git a/config/src/lib.rs b/config/src/lib.rs index 306257a..79a665e 100644 --- a/config/src/lib.rs +++ b/config/src/lib.rs @@ -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}; diff --git a/engine/preprocessor/Cargo.toml b/engine/preprocessor/Cargo.toml index 31dee9b..869fa61 100644 --- a/engine/preprocessor/Cargo.toml +++ b/engine/preprocessor/Cargo.toml @@ -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 } diff --git a/engine/preprocessor/src/lib.rs b/engine/preprocessor/src/lib.rs index d30c384..5ff4bc4 100644 --- a/engine/preprocessor/src/lib.rs +++ b/engine/preprocessor/src/lib.rs @@ -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. @@ -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!(), //! }; //! }); @@ -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 { @@ -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. @@ -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. @@ -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!(), /// }; /// }); @@ -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; @@ -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!(), }; }); @@ -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()), @@ -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 ç"); @@ -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!(), }; }); @@ -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!(), }; }); diff --git a/engine/translator/src/lib.rs b/engine/translator/src/lib.rs index 1962263..3716cb8 100644 --- a/engine/translator/src/lib.rs +++ b/engine/translator/src/lib.rs @@ -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(); @@ -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(); @@ -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(); @@ -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" { @@ -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}; @@ -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); @@ -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#" @@ -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(); @@ -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(); @@ -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();