summaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
Diffstat (limited to 'parser')
-rw-r--r--parser/src/error.rs5
-rw-r--r--parser/src/parse.rs9
-rw-r--r--parser/src/syntax_checker.rs20
3 files changed, 12 insertions, 22 deletions
diff --git a/parser/src/error.rs b/parser/src/error.rs
index b9ac888..b594165 100644
--- a/parser/src/error.rs
+++ b/parser/src/error.rs
@@ -7,6 +7,7 @@ use unicode_width::UnicodeWidthStr;
pub enum Exit {
Code(i32),
IoError(std::io::Error),
+ FileNotFound(PathBuf),
SyntaxError {
content: String,
reason: String,
@@ -28,6 +29,10 @@ pub fn handle_exit(e: Exit) {
match e {
Exit::Code(code) => exit(code),
Exit::IoError(error) => print_parse_error(error.to_string()),
+ Exit::FileNotFound(path_buf) => {
+ eprintln!("File `{}` not found!", path_buf.display());
+ exit(1)
+ }
Exit::SyntaxError {
content,
reason,
diff --git a/parser/src/parse.rs b/parser/src/parse.rs
index 79f5719..c4c69f8 100644
--- a/parser/src/parse.rs
+++ b/parser/src/parse.rs
@@ -65,8 +65,13 @@ fn expand_recursive(
if let Some(include_path) = extract_include(line) {
let include_abs = format_path(&current_path.parent().unwrap().join(include_path))?;
- let include_content =
- std::fs::read_to_string(&include_abs).map_err(|e| Exit::IoError(e))?;
+ let include_content = std::fs::read_to_string(&include_abs).map_err(|e| {
+ if e.kind() == std::io::ErrorKind::NotFound {
+ Exit::FileNotFound(include_abs.clone())
+ } else {
+ Exit::IoError(e)
+ }
+ })?;
let expanded = expand_recursive(include_content, &include_abs, stack)?;
output.push_str(&expanded);
diff --git a/parser/src/syntax_checker.rs b/parser/src/syntax_checker.rs
index c8e654c..334fa9d 100644
--- a/parser/src/syntax_checker.rs
+++ b/parser/src/syntax_checker.rs
@@ -197,25 +197,5 @@ pub fn check_markdown_syntax(i: &String) -> Result<(), Exit> {
});
}
- // Check if all anchors have corresponding headings
- for (anchor, line_num, pos) in anchors {
- // Normalize anchor for comparison: convert to lowercase and filter characters
- let normalized_anchor = anchor
- .to_lowercase()
- .chars()
- .filter(|c| c.is_alphanumeric() || *c == '-' || *c == '_')
- .collect::<String>();
-
- if !heading_ids.contains(&normalized_anchor) {
- return Err(Exit::SyntaxError {
- content: lines[(line_num - 1) as usize].to_string(),
- reason: format!("Anchor '#{}' has no corresponding heading", anchor),
- line: line_num,
- begin: pos,
- end: pos + anchor.len() as i64,
- });
- }
- }
-
Ok(())
}