From 1eb5897e4e61f4b53f9ce9af9f9b3d8509d99f88 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 25 Apr 2021 10:46:08 +0200 Subject: [PATCH] Restructure project Signed-off-by: trivernis --- src/lib.rs | 11 ++++++----- src/matching/matchers.rs | 0 src/matching/mod.rs | 0 src/tests/test_input.rs | 4 ++-- src/tests/test_lexer.rs | 8 ++++---- src/tests/test_token.rs | 6 +++--- src/tests/test_token_reader.rs | 4 ++-- src/{ => tokenizing}/lexer.rs | 8 ++++---- src/tokenizing/mod.rs | 7 +++++++ src/{ => tokenizing}/token.rs | 4 ++-- src/{ => tokenizing}/token_reader.rs | 2 +- src/{ => utils}/error.rs | 0 src/{ => utils}/input_reader.rs | 2 +- src/utils/mod.rs | 2 ++ 14 files changed, 34 insertions(+), 24 deletions(-) create mode 100644 src/matching/matchers.rs create mode 100644 src/matching/mod.rs rename src/{ => tokenizing}/lexer.rs (86%) create mode 100644 src/tokenizing/mod.rs rename src/{ => tokenizing}/token.rs (94%) rename src/{ => tokenizing}/token_reader.rs (97%) rename src/{ => utils}/error.rs (100%) rename src/{ => utils}/input_reader.rs (98%) create mode 100644 src/utils/mod.rs diff --git a/src/lib.rs b/src/lib.rs index 9e665dd..977a72a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,9 @@ -pub mod error; -pub mod input_reader; -pub mod lexer; -pub mod token; -pub mod token_reader; +pub mod matching; +pub mod tokenizing; +mod utils; + +pub use utils::error::*; +pub use utils::input_reader::InputReader; #[cfg(test)] mod tests; diff --git a/src/matching/matchers.rs b/src/matching/matchers.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/matching/mod.rs b/src/matching/mod.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/tests/test_input.rs b/src/tests/test_input.rs index 1f8331c..c8adfb6 100644 --- a/src/tests/test_input.rs +++ b/src/tests/test_input.rs @@ -1,5 +1,5 @@ -use crate::error::{TapeError, TapeResult}; -use crate::input_reader::InputReader; +use crate::InputReader; +use crate::{TapeError, TapeResult}; use std::io::Cursor; fn get_reader() -> InputReader { diff --git a/src/tests/test_lexer.rs b/src/tests/test_lexer.rs index b1362de..32d7e59 100644 --- a/src/tests/test_lexer.rs +++ b/src/tests/test_lexer.rs @@ -1,7 +1,7 @@ -use crate::error::TapeResult; -use crate::input_reader::InputReader; -use crate::lexer::Lexer; -use crate::token::{Token, TokenCheckerFn, UnknownToken}; +use crate::tokenizing::Lexer; +use crate::tokenizing::{Token, TokenCheckerFn, UnknownToken}; +use crate::InputReader; +use crate::TapeResult; use std::io::Cursor; use std::sync::Arc; diff --git a/src/tests/test_token.rs b/src/tests/test_token.rs index 16ce5e3..23f1f85 100644 --- a/src/tests/test_token.rs +++ b/src/tests/test_token.rs @@ -1,6 +1,6 @@ -use crate::error::TapeResult; -use crate::input_reader::InputReader; -use crate::token::Token; +use crate::tokenizing::Token; +use crate::InputReader; +use crate::TapeResult; use std::io::Cursor; #[derive(Debug)] diff --git a/src/tests/test_token_reader.rs b/src/tests/test_token_reader.rs index 0b7dd0f..8154744 100644 --- a/src/tests/test_token_reader.rs +++ b/src/tests/test_token_reader.rs @@ -1,5 +1,5 @@ -use crate::token::{EOFToken, Token}; -use crate::token_reader::TokenReader; +use crate::tokenizing::TokenReader; +use crate::tokenizing::{EOFToken, Token}; struct AToken; struct BToken; diff --git a/src/lexer.rs b/src/tokenizing/lexer.rs similarity index 86% rename from src/lexer.rs rename to src/tokenizing/lexer.rs index 41d8f76..bd7481d 100644 --- a/src/lexer.rs +++ b/src/tokenizing/lexer.rs @@ -1,6 +1,6 @@ -use crate::error::TapeResult; -use crate::input_reader::InputReader; -use crate::token::{EOFToken, Token, TokenCheckerFn, UnknownToken}; +use crate::tokenizing::{EOFToken, Token, TokenCheckerFn, UnknownToken}; +use crate::InputReader; +use crate::TapeResult; pub struct Lexer { reader: InputReader, @@ -13,7 +13,7 @@ impl Lexer { Self { reader, checkers } } - /// Scans for tokens + /// Scans for tokenizing pub async fn scan(&mut self) -> TapeResult> { let mut tokens = Vec::new(); diff --git a/src/tokenizing/mod.rs b/src/tokenizing/mod.rs new file mode 100644 index 0000000..a5cf8b9 --- /dev/null +++ b/src/tokenizing/mod.rs @@ -0,0 +1,7 @@ +mod lexer; +mod token; +mod token_reader; + +pub use lexer::Lexer; +pub use token::*; +pub use token_reader::TokenReader; diff --git a/src/token.rs b/src/tokenizing/token.rs similarity index 94% rename from src/token.rs rename to src/tokenizing/token.rs index affe0af..bd59445 100644 --- a/src/token.rs +++ b/src/tokenizing/token.rs @@ -1,5 +1,5 @@ -use crate::error::TapeResult; -use crate::input_reader::InputReader; +use crate::InputReader; +use crate::TapeResult; use std::any::{Any, TypeId}; use std::future::Future; use std::pin::Pin; diff --git a/src/token_reader.rs b/src/tokenizing/token_reader.rs similarity index 97% rename from src/token_reader.rs rename to src/tokenizing/token_reader.rs index d428c6c..5fb63e6 100644 --- a/src/token_reader.rs +++ b/src/tokenizing/token_reader.rs @@ -1,4 +1,4 @@ -use crate::token::{EOFToken, Token}; +use crate::tokenizing::{EOFToken, Token}; pub struct TokenReader { tokens: Vec, diff --git a/src/error.rs b/src/utils/error.rs similarity index 100% rename from src/error.rs rename to src/utils/error.rs diff --git a/src/input_reader.rs b/src/utils/input_reader.rs similarity index 98% rename from src/input_reader.rs rename to src/utils/input_reader.rs index e15f2a9..d0e38d2 100644 --- a/src/input_reader.rs +++ b/src/utils/input_reader.rs @@ -1,4 +1,4 @@ -use crate::error::{TapeError, TapeResult}; +use crate::{TapeError, TapeResult}; use std::io::ErrorKind; use tokio::io::{AsyncBufRead, AsyncBufReadExt}; diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..b38cd6b --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1,2 @@ +pub mod error; +pub mod input_reader;