#![cfg_attr(not(test), warn(missing_docs))]
pub use hedl_core::{
parse as core_parse,
parse_with_limits,
Document,
HedlError,
HedlErrorKind,
Item,
Limits,
MatrixList,
Node,
ParseOptions,
Reference,
ReferenceMode,
Tensor,
Value,
};
mod error_ext;
pub use error_ext::HedlResultExt;
pub mod lex {
pub use hedl_core::lex::{
is_valid_id_token, is_valid_key_token, is_valid_type_name, parse_reference, scan_regions,
strip_comment, validate_indent, IndentInfo, LexError, Reference, Region,
};
}
pub mod csv {
pub use hedl_core::lex::{parse_csv_row, CsvField};
}
pub mod tensor {
pub use hedl_core::lex::{parse_tensor, Tensor};
}
pub mod c14n {
pub use hedl_c14n::{
canonicalize, canonicalize_with_config, CanonicalConfig, CanonicalWriter, QuotingStrategy,
};
}
pub mod json {
pub use hedl_json::{
from_json, from_json_value, hedl_to_json, json_to_hedl, to_json, to_json_value,
FromJsonConfig, ToJsonConfig,
};
}
pub mod lint {
pub use hedl_lint::{
lint, lint_with_config, Diagnostic, DiagnosticKind, LintConfig, LintRule, LintRunner,
RuleConfig, Severity,
};
}
#[cfg(feature = "yaml")]
pub mod yaml {
pub use hedl_yaml::{
from_yaml, hedl_to_yaml, to_yaml, yaml_to_hedl, FromYamlConfig, ToYamlConfig,
};
}
#[cfg(feature = "xml")]
pub mod xml {
pub use hedl_xml::{from_xml, hedl_to_xml, to_xml, xml_to_hedl, FromXmlConfig, ToXmlConfig};
}
#[cfg(feature = "csv")]
pub mod csv_file {
pub use hedl_csv::{
from_csv, from_csv_with_config, to_csv, to_csv_with_config, FromCsvConfig, ToCsvConfig,
};
}
#[cfg(feature = "parquet")]
pub mod parquet {
pub use hedl_parquet::{
from_parquet, from_parquet_bytes, to_parquet, to_parquet_bytes, ToParquetConfig,
};
}
#[cfg(feature = "neo4j")]
pub mod neo4j {
pub use hedl_neo4j::{
build_record,
build_relationship,
from_neo4j_records,
hedl_to_cypher,
neo4j_to_hedl,
to_cypher,
to_cypher_statements,
CypherScript,
CypherStatement,
CypherValue,
FromNeo4jConfig,
Neo4jError,
Neo4jNode,
Neo4jRecord,
Neo4jRelationship,
ObjectHandling,
RelationshipNaming,
Result as Neo4jResult,
StatementType,
ToCypherConfig,
};
}
#[cfg(feature = "toon")]
pub mod toon {
pub use hedl_toon::{
hedl_to_toon, to_toon, Delimiter, ToToonConfig, ToToonConfigBuilder, ToonError,
};
}
#[inline]
pub fn parse(input: &str) -> Result<Document, HedlError> {
core_parse(input.as_bytes())
}
#[inline]
pub fn parse_lenient(input: &str) -> Result<Document, HedlError> {
let options = ParseOptions {
reference_mode: hedl_core::ReferenceMode::Lenient,
..Default::default()
};
parse_with_limits(input.as_bytes(), options)
}
#[inline]
pub fn canonicalize(doc: &Document) -> Result<String, HedlError> {
hedl_c14n::canonicalize(doc)
}
#[inline]
pub fn to_json(doc: &Document) -> Result<String, HedlError> {
hedl_json::to_json(doc, &hedl_json::ToJsonConfig::default())
.map_err(|e| HedlError::syntax(format!("JSON conversion error: {e}"), 0))
}
#[inline]
pub fn from_json(json: &str) -> Result<Document, HedlError> {
hedl_json::from_json(json, &hedl_json::FromJsonConfig::default())
.map_err(|e| HedlError::syntax(format!("JSON conversion error: {e}"), 0))
}
#[inline]
#[must_use]
pub fn lint(doc: &Document) -> Vec<lint::Diagnostic> {
hedl_lint::lint(doc)
}
#[inline]
pub fn validate(input: &str) -> Result<(), HedlError> {
parse(input).map(|_| ())
}
pub const SUPPORTED_VERSION: (u32, u32) = (2, 0);
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parse_minimal() {
let doc = parse("%VERSION: 1.0\n---\n").unwrap();
assert_eq!(doc.version, (1, 0));
}
#[test]
fn test_parse_key_value() {
let doc = parse("%VERSION: 1.0\n---\nkey: value\nnum: 42").unwrap();
assert_eq!(doc.version, (1, 0));
}
#[test]
fn test_parse_matrix_list() {
let input = r"
%VERSION: 1.0
%STRUCT: User: [id,name]
---
users:@User
|alice,Alice
|bob,Bob
";
let doc = parse(input).unwrap();
assert!(doc.structs.contains_key("User"));
}
#[test]
fn test_canonicalize() {
let doc = parse("%VERSION: 1.0\n---\nb: 2\na: 1").unwrap();
let canonical = canonicalize(&doc).unwrap();
let a_pos = canonical.find("a:").unwrap();
let b_pos = canonical.find("b:").unwrap();
assert!(a_pos < b_pos);
}
#[test]
fn test_to_json() {
let doc = parse("%VERSION: 1.0\n---\nkey: 42").unwrap();
let json = to_json(&doc).unwrap();
assert!(json.contains("42"));
}
#[test]
fn test_validate() {
assert!(validate("%VERSION: 1.0\n---\n").is_ok());
assert!(validate("invalid").is_err());
}
}