Skip to content

Commit

Permalink
Merge pull request #6 from kb10uy/dedicate-transformer
Browse files Browse the repository at this point in the history
Compiler v2
  • Loading branch information
kb10uy authored Nov 26, 2023
2 parents 48850d4 + 1970ca2 commit 5ad682e
Show file tree
Hide file tree
Showing 34 changed files with 2,781 additions and 3,296 deletions.
203 changes: 67 additions & 136 deletions Cargo.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions avatar-validator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ version = "0.1.0"
edition = "2021"

[dependencies]
anyhow = "1.0.70"
clap = { version = "4.2.1", features = ["derive"] }
anyhow = "1.0.75"
clap = { version = "4.4.8", features = ["derive"] }
declavatar = { path = "../declavatar" }
miette = { version = "5.7.0", features = ["fancy"] }
serde_json = "1.0.95"
miette = { version = "5.10.0", features = ["fancy"] }
serde_json = "1.0.108"

[build-dependencies]
static_vcruntime = { version = "2.0.0" }
13 changes: 7 additions & 6 deletions avatar-validator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
};

use clap::Parser;
use declavatar::{avatar::compile_avatar, decl::parse_document};
use declavatar::{avatar::transform_avatar, decl::parse_document};
use miette::{IntoDiagnostic, Result as MietteResult};

fn main() -> MietteResult<()> {
Expand All @@ -19,11 +19,12 @@ fn main() -> MietteResult<()> {
file.read_to_string(&mut source).into_diagnostic()?;

let document = parse_document(&source)?;
let avatar = match compile_avatar(document.avatar)? {
Ok(avatar) => avatar,
Err(errors) => {
for error in errors {
println!("{error}");
let transformed = transform_avatar(document.avatar);
let avatar = match transformed.avatar {
Some(avatar) => avatar,
None => {
for (level, message) in transformed.logs {
println!("{level:?}: {message}");
}
return Ok(());
}
Expand Down
12 changes: 6 additions & 6 deletions declavatar/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "declavatar"
version = "0.7.0"
version = "0.9.0"
edition = "2021"

[features]
Expand All @@ -11,11 +11,11 @@ crate-type = ["rlib", "cdylib"]

[dependencies]
kdl = "4.6.0"
miette = "5.7.0"
semver = "1.0.17"
serde = { version = "1.0.160", features = ["derive"] }
serde_json = "1.0.95"
thiserror = "1.0.40"
miette = "5.10.0"
semver = "1.0.20"
serde = { version = "1.0.193", features = ["derive"] }
serde_json = "1.0.108"
thiserror = "1.0.50"

[build-dependencies]
static_vcruntime = { version = "2.0.0" }
27 changes: 27 additions & 0 deletions declavatar/src/avatar.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
pub mod data;
pub mod error;

mod transformer;

pub use self::transformer::LogLevel;

use crate::{
avatar::{
data::Avatar,
transformer::{compile_avatar, Context},
},
decl::data::Avatar as DeclAvatar,
};

pub struct TransformResult {
pub avatar: Option<Avatar>,
pub logs: Vec<(LogLevel, String)>,
}

pub fn transform_avatar(avatar: DeclAvatar) -> TransformResult {
let mut ctx = Context::new();
let avatar = compile_avatar(&mut ctx, avatar);
let logs = ctx.into_logs();

TransformResult { avatar, logs }
}
Loading

0 comments on commit 5ad682e

Please sign in to comment.