Skip to content

Commit

Permalink
renamed legacy moudles to *_legacy
Browse files Browse the repository at this point in the history
  • Loading branch information
lexa-diky committed May 9, 2024
1 parent b4c6fdf commit c32bc2d
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
8 changes: 4 additions & 4 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -150,7 +150,7 @@ pub(crate) fn run_build(source: String, output: Option<String>) -> 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))
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/cst/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -253,7 +254,7 @@ fn parse_atom_hex_into(node: &AstNode, buf: &mut Vec<CstAtom>) -> 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)
})?;
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/util/encoding.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pub(crate) fn decode_bytes_from_string(s: &String) -> Result<Vec<u8>, ()> {
(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()
}
1 change: 1 addition & 0 deletions src/compiler/util/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod byte_buffer;
pub(crate) mod encoding;

pub(crate) use byte_buffer::ByteBuffer;
6 changes: 3 additions & 3 deletions src/cst_legacy.rs
Original file line number Diff line number Diff line change
@@ -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<CstAtom>);
Expand Down Expand Up @@ -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 => {
Expand Down
15 changes: 1 addition & 14 deletions src/encoding.rs → src/encoding_legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,6 @@ pub(crate) fn decode_byte(s: String) -> Result<Vec<u8>, ()> {
.collect()
}

pub(crate) fn decode_byte_ref(s: &String) -> Result<Vec<u8>, ()> {
(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<u8> {
let mut bytes = Vec::new();
let mut value = value;
Expand All @@ -36,7 +23,7 @@ pub(crate) fn to_shrunk_bytes(value: u32) -> Vec<u8> {

#[cfg(test)]
mod tests {
use crate::encoding::decode_byte;
use crate::encoding_legacy::decode_byte;

#[test]
fn given_valid_bytes_then_decode() {
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit c32bc2d

Please sign in to comment.