From c32bc2df0985bf8b76b04f9ad9a185f81d4ea568 Mon Sep 17 00:00:00 2001 From: Aleksey Yakovlev Date: Thu, 9 May 2024 14:39:46 +0700 Subject: [PATCH] renamed legacy moudles to *_legacy --- src/cli.rs | 8 ++++---- src/compiler/cst/parser.rs | 5 +++-- src/compiler/util/encoding.rs | 11 +++++++++++ src/compiler/util/mod.rs | 1 + src/cst_legacy.rs | 6 +++--- src/{encoding.rs => encoding_legacy.rs} | 15 +-------------- src/main.rs | 6 +++--- src/{render.rs => render_legacy.rs} | 0 src/{resolver.rs => resolver_legacy.rs} | 0 9 files changed, 26 insertions(+), 26 deletions(-) create mode 100644 src/compiler/util/encoding.rs rename src/{encoding.rs => encoding_legacy.rs} (88%) rename src/{render.rs => render_legacy.rs} (100%) rename src/{resolver.rs => resolver_legacy.rs} (100%) diff --git a/src/cli.rs b/src/cli.rs index 5c7a168..768e44f 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -12,10 +12,10 @@ use notify::EventKind::Modify; use notify::{Event, RecursiveMode, Watcher}; use pest::Parser as PestParser; -use crate::resolver::resolve_cst; -use crate::{cst_legacy, render}; +use crate::resolver_legacy::resolve_cst; +use crate::{cst_legacy, render_legacy}; use crate::compiler::ast::{AstParser, AstParserError}; -use crate::render::RenderError; +use crate::render_legacy::RenderError; #[derive(Parser)] #[command(version, about, long_about = None)] @@ -150,7 +150,7 @@ pub(crate) fn run_build(source: String, output: Option) -> Result<(), Cl File::create(output_file_path) .map_err(|err| CliError::CantCrateOutputFile(err))? .write_all( - &render::render_cst(resolved_cst) + &render_legacy::render_cst(resolved_cst) .map_err(CliError::Rendering)?, ) .map_err(|err| CliError::CantCrateOutputFile(err)) diff --git a/src/compiler/cst/parser.rs b/src/compiler/cst/parser.rs index a2e8661..ea0a6fb 100644 --- a/src/compiler/cst/parser.rs +++ b/src/compiler/cst/parser.rs @@ -3,7 +3,8 @@ use std::path::PathBuf; use crate::compiler::ast::{AstNode, AstNodeType}; use crate::compiler::cst::{CstActualParameter, CstAtom, CstConstantStatement, CstEmitStatement, CstFunctionStatement}; use crate::compiler::cst::node::CstFile; -use crate::encoding; +use crate::compiler::util::encoding::decode_bytes_from_string; +use crate::encoding_legacy; #[derive(Debug)] pub(crate) enum CstParserError { @@ -253,7 +254,7 @@ fn parse_atom_hex_into(node: &AstNode, buf: &mut Vec) -> Result<(), Cst let content = node.clone().content .ok_or(CstParserError::MissingContent { node_type: AstNodeType::AtomHex })?; - let bytes = encoding::decode_byte_ref(&content) + let bytes = decode_bytes_from_string(&content) .map_err(|x| CstParserError::MalformedNodeValue { message: format!("can't parse bytes {}", content) })?; diff --git a/src/compiler/util/encoding.rs b/src/compiler/util/encoding.rs new file mode 100644 index 0000000..f83047f --- /dev/null +++ b/src/compiler/util/encoding.rs @@ -0,0 +1,11 @@ +pub(crate) fn decode_bytes_from_string(s: &String) -> Result, ()> { + (0..s.len()) + .step_by(2) + .map(|i| { + if s.len() < 2 { + return Err(()); + } + u8::from_str_radix(&s[i..i + 2], 16).map_err(|_| ()) + }) + .collect() +} diff --git a/src/compiler/util/mod.rs b/src/compiler/util/mod.rs index fb9c0de..bccaf8d 100644 --- a/src/compiler/util/mod.rs +++ b/src/compiler/util/mod.rs @@ -1,3 +1,4 @@ mod byte_buffer; +pub(crate) mod encoding; pub(crate) use byte_buffer::ByteBuffer; \ No newline at end of file diff --git a/src/cst_legacy.rs b/src/cst_legacy.rs index 8ec2b9f..2aaf297 100644 --- a/src/cst_legacy.rs +++ b/src/cst_legacy.rs @@ -1,7 +1,7 @@ use crate::compiler::ast::{AstNode, AstNodeType}; use crate::cst_legacy::CstParseError::NodeValueMissing; -use crate::encoding; -use crate::encoding::to_shrunk_bytes; +use crate::encoding_legacy; +use crate::encoding_legacy::to_shrunk_bytes; #[derive(Debug, Clone)] pub(crate) struct CstAtomStrip(Vec); @@ -257,7 +257,7 @@ fn parse_cst_atom(node: AstNode) -> CstAtom { } AstNodeType::AtomHex => { return CstAtom::Resolved { - value: encoding::decode_byte(node_value.unwrap()).unwrap(), + value: encoding_legacy::decode_byte(node_value.unwrap()).unwrap(), }; } AstNodeType::AtomConst => { diff --git a/src/encoding.rs b/src/encoding_legacy.rs similarity index 88% rename from src/encoding.rs rename to src/encoding_legacy.rs index 0860112..b278b09 100644 --- a/src/encoding.rs +++ b/src/encoding_legacy.rs @@ -11,19 +11,6 @@ pub(crate) fn decode_byte(s: String) -> Result, ()> { .collect() } -pub(crate) fn decode_byte_ref(s: &String) -> Result, ()> { - (0..s.len()) - .step_by(2) - .map(|i| { - if s.len() < 2 { - return Err(()); - } - u8::from_str_radix(&s[i..i + 2], 16).map_err(|_| ()) - }) - .collect() -} - - pub(crate) fn to_shrunk_bytes(value: u32) -> Vec { let mut bytes = Vec::new(); let mut value = value; @@ -36,7 +23,7 @@ pub(crate) fn to_shrunk_bytes(value: u32) -> Vec { #[cfg(test)] mod tests { - use crate::encoding::decode_byte; + use crate::encoding_legacy::decode_byte; #[test] fn given_valid_bytes_then_decode() { diff --git a/src/main.rs b/src/main.rs index f8aa8fe..8208e27 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,9 +9,9 @@ use crate::compiler::{FileCompilerSource, HexoCompiler, HexoCompilerContext, Str mod cli; mod cst_legacy; -mod encoding; -mod render; -mod resolver; +mod encoding_legacy; +mod render_legacy; +mod resolver_legacy; mod compiler; fn main() { diff --git a/src/render.rs b/src/render_legacy.rs similarity index 100% rename from src/render.rs rename to src/render_legacy.rs diff --git a/src/resolver.rs b/src/resolver_legacy.rs similarity index 100% rename from src/resolver.rs rename to src/resolver_legacy.rs