summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2026-03-04 01:52:49 +0100
committerThomas Voss <mail@thomasvoss.com> 2026-03-04 02:00:13 +0100
commitbba59647ed4805cdbc14bc3254acc14053846e2e (patch)
tree61c0f8f2c3adcdd1803de485a707d1ed3cb5e986
parent35989b69510400cc6a28190e415687a847cd5a40 (diff)
Better handling of -s/--error-style
-rw-r--r--oryxc/src/errors.rs3
-rw-r--r--oryxc/src/main.rs15
2 files changed, 9 insertions, 9 deletions
diff --git a/oryxc/src/errors.rs b/oryxc/src/errors.rs
index e1f72cd..9cc27cc 100644
--- a/oryxc/src/errors.rs
+++ b/oryxc/src/errors.rs
@@ -25,9 +25,10 @@ use crate::unicode;
const TAB_AS_SPACES: &'static str = " ";
const TABSIZE: usize = TAB_AS_SPACES.len();
-#[derive(Clone, Copy, Eq, PartialEq)]
+#[derive(Clone, Copy, Default, Eq, PartialEq)]
pub enum ErrorStyle {
OneLine,
+ #[default]
Standard,
}
diff --git a/oryxc/src/main.rs b/oryxc/src/main.rs
index 1b5577f..aa350e8 100644
--- a/oryxc/src/main.rs
+++ b/oryxc/src/main.rs
@@ -22,6 +22,7 @@ pub struct Flags {
pub debug_parser: bool,
pub help: bool,
pub threads: usize,
+ pub error_style: errors::ErrorStyle,
}
impl Flags {
@@ -39,15 +40,12 @@ impl Flags {
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 */
- let _ = 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")?,
- },
- );
+ flags.error_style = match parser.value()?.to_str().unwrap() {
+ "oneline" => errors::ErrorStyle::OneLine,
+ "standard" => errors::ErrorStyle::Standard,
+ s => Err(format!("{s}: invalid value for -s/--error-style"))?,
+ };
},
Short('t') | Long("threads") => {
flags.threads = parser.value()?.parse()?;
@@ -99,5 +97,6 @@ fn main() {
process::exit(0);
}
+ let _ = errors::ERROR_STYLE.set(flags.error_style);
compiler::start(rest, flags);
}