use crate::error::YamlError;
use crate::error::enhanced::{EnhancedError, ErrorCode};
use crate::parser::token_stream::TokenStream;
pub fn mapping_key_without_value_expected_value_after_colon(
stream: &mut TokenStream,
) -> EnhancedError {
EnhancedError::new(crate::parser::utils::error_builder::mapping_key_error_yaml(
stream.source_mut(),
"YAML compliance error: Mapping key without value (expected value after colon)",
))
.with_code(ErrorCode::E001)
}
pub fn invalid_indentation_after_comment_in_mapping_value(
stream: &mut TokenStream,
) -> EnhancedError {
EnhancedError::new(crate::parser::utils::error_builder::mapping_key_error_yaml(
stream.source_mut(),
"Invalid indentation after comment: indented content cannot extend a completed scalar mapping value",
))
.with_code(ErrorCode::E007)
.with_note("Check for misplaced comments or indentation.")
}
pub fn invalid_indentation_extending_completed_mapping_value(
stream: &mut TokenStream,
) -> EnhancedError {
EnhancedError::new(crate::parser::utils::error_builder::mapping_key_error_yaml(
stream.source_mut(),
"Invalid indentation: indented content cannot extend a completed mapping value",
))
.with_code(ErrorCode::E010)
.with_note(
"Ensure nested content follows keys with omitted values (e.g., 'key:\n nested: 1').",
)
}
pub fn inconsistent_dedent_within_mapping_value_for_keys(
stream: &mut TokenStream,
) -> EnhancedError {
EnhancedError::new(crate::parser::utils::error_builder::mapping_key_error_yaml(
stream.source_mut(),
"Invalid indentation for nested mapping key: inconsistent dedent within mapping value",
))
.with_code(ErrorCode::E009)
.with_note("Ensure all keys under the nested mapping use the same indentation.")
}
pub fn wrong_indentation_in_mapping(stream: &mut TokenStream) -> EnhancedError {
EnhancedError::new(crate::parser::utils::error_builder::mapping_key_error_yaml(
stream.source_mut(),
"Wrong indentation in mapping: key is more indented than the mapping's base level",
))
.with_code(ErrorCode::E009)
.with_note(
"All keys in a block mapping must be at the same indentation level. \
A more-indented key after a completed key-value pair is invalid (YAML §8.1).",
)
}
pub fn invalid_anchored_alias_key_on_alias_nodes(stream: &mut TokenStream) -> EnhancedError {
let base = crate::parser::errors::anchor_errors::AnchorErrors::invalid_anchored_alias(stream);
EnhancedError::new(base)
.with_code(ErrorCode::E004)
.with_note("Anchors are not allowed on alias nodes.")
}
pub fn multiple_anchors_on_mapping_key(stream: &mut TokenStream) -> EnhancedError {
EnhancedError::new(crate::parser::utils::error_builder::mapping_key_error_yaml(
stream.source_mut(),
"A mapping key cannot have multiple anchors",
))
.with_code(ErrorCode::E005)
.with_note("A key can only have one anchor.")
}
pub fn invalid_trailing_plain_text_after_quoted_scalar(stream: &mut TokenStream) -> YamlError {
crate::parser::utils::error_builder::syntax_error(
stream.source_mut(),
"Invalid content immediately after quoted scalar: trailing plain text on the same line is not allowed",
)
}
pub fn implicit_key_without_colon_at_eof(stream: &mut TokenStream) -> YamlError {
crate::parser::utils::error_builder::syntax_error(
stream.source_mut(),
"YAML compliance error: Implicit mapping key has no ':' value separator (comment cannot substitute for ':')",
)
}
pub fn nested_key_separator_in_block_value_same_line(stream: &mut TokenStream) -> YamlError {
crate::parser::utils::error_builder::syntax_error(
stream.source_mut(),
"Invalid mapping value: unexpected ':' immediately after value on the same line",
)
}
pub fn block_sequence_inline_on_mapping_value_line(stream: &mut TokenStream) -> YamlError {
crate::parser::utils::error_builder::syntax_error(
stream.source_mut(),
"Invalid mapping value: block sequence entry '-' cannot appear on the same line as the mapping key; use a new indented line",
)
}
pub fn expected_explicit_key_token(
stream: &mut TokenStream,
cur: Option<crate::parser::lexer::Token>,
) -> YamlError {
crate::parser::utils::error_builder::syntax_error(
stream.source_mut(),
&format!("Expected '?' token for explicit key, got {:?}", cur),
)
}