diff options
| author | tslil <tslil@posteo.de> | 2026-05-04 17:52:04 +0100 |
|---|---|---|
| committer | tslil <tslil@posteo.de> | 2026-05-04 18:26:43 +0100 |
| commit | 90e451893671ceebaa37fcb634b5d7a3f153ba70 (patch) | |
| tree | b7d21bc968fed9141c74b6cb00ec3a3ae1e577ed /src/parser.rs | |
| parent | 3ce914fdc62923c92812037297aee64747a9867e (diff) | |
almost done
Diffstat (limited to 'src/parser.rs')
| -rw-r--r-- | src/parser.rs | 16 |
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 + )) } } } |
