summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2026-03-02 22:12:06 +0100
committerThomas Voss <mail@thomasvoss.com> 2026-03-02 22:12:06 +0100
commitb903ea3d09abf7aba9c415c37b205076b1bc1631 (patch)
treed88110f025409fadbb326eace3c43c7d56ed1f11
parentc05f72244edb9f7cd7566f4457d2052ff02e6791 (diff)
Add different error styles
-rw-r--r--oryxc/src/errors.rs15
-rw-r--r--oryxc/src/main.rs16
2 files changed, 30 insertions, 1 deletions
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<ErrorStyle> = OnceLock::new();
+
pub fn progname() -> &'static OsString {
static ARGV0: OnceLock<OsString> = 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()
);
}