aboutsummaryrefslogtreecommitdiff
path: root/src/parser.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.rs')
-rw-r--r--src/parser.rs16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/parser.rs b/src/parser.rs
index 285bb84..4e41644 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -269,23 +269,21 @@ parser! {
}
}
-pub fn parse(src: &str) -> Programme {
+pub fn parse_result(src: &str) -> Result<Programme, String> {
match parser::program(src) {
- Ok(p) => {
- println!("{}", p);
- p
- }
+ Ok(p) => Ok(p),
Err(e) => {
let line = e.location.line;
let col = e.location.column;
let off = e.location.offset;
- println!("FAIL at {}:{} (offset {})", line, col, off);
- println!("expected: {:#}", e.expected);
let before = &src[off.saturating_sub(40)..off];
let after = &src[off..(off + 40).min(src.len())];
- println!("...{}⟨HERE⟩{}...", before, after);
- panic!("Parse failed!");
+
+ Err(format!(
+ "FAIL at {}:{} (offset {})\nexpected: {:#?}\n...{}⟨HERE⟩{}...",
+ line, col, off, e.expected, before, after
+ ))
}
}
}