better logs

This commit is contained in:
brevalferrari 2025-06-05 18:45:13 +02:00
parent 03ded1fb74
commit 52cbb88a6d
2 changed files with 23 additions and 20 deletions

View file

@ -10,7 +10,7 @@ use cfg_if::cfg_if;
use derive_new::new;
use derive_wrapper::{AsRef, From};
use fasteval::{Compiler as _, EvalNamespace, Evaler, Instruction, Slab};
use log::trace;
use log::{debug, trace};
use thiserror::Error;
cfg_if! {
@ -74,7 +74,7 @@ pub struct Silence;
impl Token for Silence {
fn apply(&self, context: Context) -> Result<Context, CompilerError> {
trace!("⚡ {}", type_name::<Self>());
debug!("⚡ {}", type_name::<Self>());
let (mut context, mut next) = context.render(None)?;
context.result.append(&mut next);
Ok(context)
@ -87,7 +87,7 @@ pub struct Marker;
impl Token for Marker {
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
trace!("⚡ {}", type_name::<Self>());
debug!("⚡ {}", type_name::<Self>());
context.result.clear();
Ok(context)
}
@ -99,7 +99,7 @@ pub struct Note(pub u8);
impl Token for Note {
fn apply(&self, context: Context) -> Result<Context, CompilerError> {
trace!("⚡ {}", type_name::<Self>());
debug!("⚡ {}", type_name::<Self>());
let (mut context, mut next) = context.render(Some(self.0))?;
context.result.append(&mut next);
Ok(context)
@ -118,7 +118,7 @@ impl AsRef<VariableChange> for VariableChange {
impl Token for VariableChange {
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
trace!("⚡ {}", type_name::<Self>());
debug!("⚡ {}", type_name::<Self>());
*context.get_mut(self.0.to_string())? = context.eval(self.1.as_ref())?;
Ok(context)
}
@ -143,7 +143,7 @@ impl Default for LoopCount {
impl Token for Loop {
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
trace!("⚡ {}", type_name::<Self>());
debug!("⚡ {}", type_name::<Self>());
let mut old_result = context.result.clone();
let count = match self.0 {
LoopCount::Litteral(n) => n,
@ -169,7 +169,7 @@ pub struct Tuplet(pub TokenVec);
impl Token for Tuplet {
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
trace!("⚡ {}", type_name::<Self>());
debug!("⚡ {}", type_name::<Self>());
let mut old_result = context.result.clone();
context.result.clear();
let mut new_context = self
@ -207,7 +207,7 @@ pub struct Slope(pub VariableChange, pub TokenVec);
impl Token for Slope {
fn apply(&self, mut context: Context) -> Result<Context, CompilerError> {
trace!("⚡ {}", type_name::<Self>());
debug!("⚡ {}", type_name::<Self>());
context.slopes.push((
self.0.as_ref().0.to_string(),
self.0.as_ref().1.as_ref().clone(),
@ -402,13 +402,16 @@ impl Context {
pub fn eval_with(
Expression {
from: _,
from,
instruction,
slab,
}: &Expression,
ns: &mut impl EvalNamespace,
) -> Result<f64, fasteval::Error> {
instruction.eval(slab, ns)
instruction
.eval(slab, ns)
.inspect(|ok| trace!("{from} = {ok}"))
.inspect_err(|e| trace!("{from} = {e}"))
}
pub fn render(mut self, n: Option<u8>) -> Result<(Self, Vec<f64>), CompilerError> {

View file

@ -74,7 +74,7 @@ where
SV: Borrow<VariableChange>,
V: AsRef<[char]>,
{
debug!("making the TOKEN parser");
trace!("making the TOKEN parser");
let space_or_comment = || {
value(
(),
@ -107,7 +107,7 @@ impl Silence {
I: Input,
<I as Input>::Item: AsChar,
{
debug!("making the {} parser", type_name::<Self>());
trace!("making the {} parser", type_name::<Self>());
value(Self, char('.'))
}
}
@ -118,7 +118,7 @@ impl Marker {
I: Input,
<I as Input>::Item: AsChar,
{
debug!("making the {} parser", type_name::<Self>());
trace!("making the {} parser", type_name::<Self>());
value(Marker, char('%'))
}
}
@ -132,7 +132,7 @@ impl Note {
NS: AsRef<str>,
I: Input + for<'z> Compare<&'z str>,
{
debug!("making the {} parser", type_name::<Self>());
trace!("making the {} parser", type_name::<Self>());
let notes = {
let mut sorted = notes
.into_iter()
@ -167,7 +167,7 @@ impl VariableChange {
<I as Input>::Item: AsChar,
V: AsRef<[char]>,
{
debug!("making the {} parser", type_name::<Self>());
trace!("making the {} parser", type_name::<Self>());
move |i: I| {
preceded(
char('$'),
@ -195,7 +195,7 @@ impl Loop {
SV: Borrow<VariableChange>,
V: AsRef<[char]>,
{
debug!("making the {} parser", type_name::<Self>());
trace!("making the {} parser", type_name::<Self>());
move |input| {
delimited(
char('('),
@ -235,7 +235,7 @@ impl Tuplet {
SV: Borrow<VariableChange>,
V: AsRef<[char]>,
{
debug!("making the {} parser", type_name::<Self>());
trace!("making the {} parser", type_name::<Self>());
|input| {
delimited(char('['), token_parser(parser), char(']'))
.map(Self)
@ -259,7 +259,7 @@ impl Slope {
SV: Borrow<VariableChange>,
V: AsRef<[char]>,
{
debug!("making the {} parser", type_name::<Self>());
trace!("making the {} parser", type_name::<Self>());
move |input| {
let slopes = {
let mut vec = parser
@ -300,7 +300,7 @@ where
V: IntoIterator<Item = C>,
C: Borrow<char>,
{
debug!("making the Expression parser");
trace!("making the Expression parser");
let variables: Vec<(String, f64)> = variables
.into_iter()
.map(|v| (v.borrow().to_string(), 0.0))
@ -347,7 +347,7 @@ where
I: Input + Copy,
F: Fn(I) -> Option<O>,
{
debug!("making take_while_map parser");
trace!("making take_while_map parser");
move |input: I| {
let mut len = input.input_len();
debug!(