From b903ea3d09abf7aba9c415c37b205076b1bc1631 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 2 Mar 2026 22:12:06 +0100 Subject: Add different error styles --- oryxc/src/errors.rs | 15 +++++++++++++++ oryxc/src/main.rs | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) (limited to 'oryxc/src') diff --git a/oryxc/src/errors.rs b/oryxc/src/errors.rs index b2bab4e..5332d17 100644 --- a/oryxc/src/errors.rs +++ b/oryxc/src/errors.rs @@ -27,6 +27,14 @@ use crate::unicode; const TAB_AS_SPACES: &'static str = " "; const TABSIZE: usize = TAB_AS_SPACES.len(); +#[derive(Clone, Copy, Eq, PartialEq)] +pub enum ErrorStyle { + OneLine, + Standard, +} + +pub static ERROR_STYLE: OnceLock = OnceLock::new(); + pub fn progname() -> &'static OsString { static ARGV0: OnceLock = OnceLock::new(); return ARGV0.get_or_init(|| { @@ -153,6 +161,13 @@ impl OryxError { "{FNAMEBEG}{}:{line}:{col}:{FMTEND} {ERRORBEG}error:{FMTEND} {self}\n", filename.as_ref().display() ); + + if *ERROR_STYLE.get_or_init(|| ErrorStyle::Standard) + == ErrorStyle::OneLine + { + return; + } + let _ = write!( handle, " {line:>4} │ {errbeg}{ERRORBEG}{errmid}{FMTEND}{errend}\n" diff --git a/oryxc/src/main.rs b/oryxc/src/main.rs index 60733fb..d0ce286 100644 --- a/oryxc/src/main.rs +++ b/oryxc/src/main.rs @@ -37,6 +37,17 @@ impl Flags { Short('h') | Long("help") => flags.help = true, Short('l') | Long("debug-lexer") => flags.debug_lexer = true, Short('p') | Long("debug-parser") => flags.debug_parser = true, + Short('s') | Long("error-style") => { + /* TODO: Check for error (user could pass the flag twice) */ + /* TODO: Don’t unwrap */ + errors::ERROR_STYLE.set( + match parser.value()?.to_str().unwrap() { + "oneline" => errors::ErrorStyle::OneLine, + "standard" => errors::ErrorStyle::Standard, + _ => Err("invalid value for -s/--error-style")?, + }, + ); + }, Short('t') | Long("threads") => { flags.threads = parser.value()?.parse()?; if flags.threads == 0 { @@ -64,7 +75,10 @@ impl Flags { fn usage() { eprintln!( - concat!("Usage: {0} [-lp] [-t threads]\n", " {0} -h"), + concat!( + "Usage: {0} [-lp] [-s oneline|standard] [-t threads]\n", + " {0} -h", + ), errors::progname().display() ); } -- cgit v1.2.3