#![warn(missing_docs)]
pub mod error;
pub mod serde_support;
pub mod tauq;
pub mod tbf;
pub mod c_bindings;
#[cfg(feature = "java-bindings")]
pub mod java_bindings;
#[cfg(feature = "python-bindings")]
pub mod python_bindings;
#[cfg(feature = "iceberg")]
pub mod tbf_iceberg;
pub use error::TauqError;
pub use serde_support::{from_bytes, from_file, from_str};
pub use tauq::Delimiter;
pub use tauq::{Formatter, Lexer, Parser, StreamingParser};
pub use tauq::{json_to_tauq, json_to_tauq_optimized, json_to_tauq_ultra, minify_tauq};
pub const MAX_INPUT_SIZE: usize = 100 * 1024 * 1024;
pub const MAX_NESTING_DEPTH: usize = 100;
pub fn compile_tauq(source: &str) -> Result<serde_json::Value, error::TauqError> {
if source.len() > MAX_INPUT_SIZE {
return Err(error::TauqError::Interpret(error::InterpretError::new(
format!(
"Input too large: {} bytes (max {} bytes)",
source.len(),
MAX_INPUT_SIZE
),
)));
}
let mut parser = tauq::Parser::new(source);
let result = parser.parse().map_err(error::TauqError::Parse)?;
Ok(result)
}
pub fn compile_tauqq_safe(source: &str) -> Result<serde_json::Value, error::TauqError> {
compile_tauqq(source, true)
}
pub fn compile_tauqq_unsafe(source: &str) -> Result<serde_json::Value, error::TauqError> {
compile_tauqq(source, false)
}
pub fn compile_tauqq(source: &str, safe_mode: bool) -> Result<serde_json::Value, error::TauqError> {
let processed = process_tauqq(source, safe_mode)?;
compile_tauq(&processed)
}
pub fn process_tauqq(source: &str, safe_mode: bool) -> Result<String, error::TauqError> {
if source.len() > MAX_INPUT_SIZE {
return Err(error::TauqError::Interpret(error::InterpretError::new(
format!(
"Input too large: {} bytes (max {} bytes)",
source.len(),
MAX_INPUT_SIZE
),
)));
}
let mut vars = std::collections::HashMap::new();
tauq::tauqq::process(source, &mut vars, safe_mode)
.map_err(|e| error::TauqError::Interpret(error::InterpretError::new(e)))
}
pub fn format_to_tauq(json: &serde_json::Value) -> String {
tauq::json_to_tauq(json)
}
pub fn minify_tauq_str(json: &serde_json::Value) -> String {
tauq::minify_tauq(json)
}
pub fn print_error_with_source(source: &str, error: &error::TauqError) {
let span = match error {
error::TauqError::Lex(e) => Some(e.span),
error::TauqError::Parse(e) => Some(e.span),
error::TauqError::Interpret(e) => e.span,
error::TauqError::Io(_) => None,
};
if let Some(span) = span {
let lines: Vec<&str> = source.lines().collect();
if span.line > 0 && span.line <= lines.len() {
let line_idx = span.line - 1;
let line = lines[line_idx];
eprintln!("Error: {}", error);
eprintln!(" |");
eprintln!("{:2} | {}", span.line, line);
let mut pointer = String::new();
for _ in 0..span.column {
pointer.push(' ');
}
pointer.push('^');
eprintln!(" | {}", pointer);
eprintln!(" |");
} else {
eprintln!("Error: {}", error);
}
} else {
eprintln!("Error: {}", error);
}
}