use crate::{
ast::{expressions::DatexExpression, spanned::Spanned},
decompiler::DecompileOptions,
prelude::*,
traits::to_datex_expression_data::ToDatexExpressionData,
};
use apply_syntax_highlighting::apply_syntax_highlighting;
use converter::AstToSourceCodeConverter;
pub mod apply_syntax_highlighting;
mod converter;
pub fn value_to_source_code(
value: &impl ToDatexExpressionData,
options: DecompileOptions,
) -> String {
let ast = value.to_datex_expression_data().with_default_span();
ast_to_source_code(ast, options)
}
pub fn value_to_source_code_default(
value: &impl ToDatexExpressionData,
) -> String {
value_to_source_code(value, DecompileOptions::default())
}
pub fn ast_to_source_code(
ast: DatexExpression,
options: DecompileOptions,
) -> String {
let colorized = options.formatting_options.colorized;
let converter = AstToSourceCodeConverter::new(options.formatting_options);
let source = converter.format(&ast);
if colorized {
apply_syntax_highlighting(source).unwrap()
} else {
source
}
}