summaryrefslogtreecommitdiff
path: root/oryxc/src
diff options
context:
space:
mode:
Diffstat (limited to 'oryxc/src')
-rw-r--r--oryxc/src/compiler.rs23
-rw-r--r--oryxc/src/errors.rs11
-rw-r--r--oryxc/src/main.rs21
3 files changed, 36 insertions, 19 deletions
diff --git a/oryxc/src/compiler.rs b/oryxc/src/compiler.rs
index 2a0a3c9..a83cf45 100644
--- a/oryxc/src/compiler.rs
+++ b/oryxc/src/compiler.rs
@@ -187,13 +187,11 @@ fn worker_loop(
match job {
Job::Lex { file, fdata } => {
- let tokens = match lexer::tokenize(&fdata.buffer) {
- Ok(xs) => xs,
- Err(e) => {
+ let tokens =
+ lexer::tokenize(&fdata.buffer).unwrap_or_else(|e| {
emit_errors(&fdata, once(e));
process::exit(1)
- },
- };
+ });
if state.flags.debug_lexer {
let mut handle = io::stderr().lock();
@@ -207,14 +205,13 @@ fn worker_loop(
state.push_job(&queue, Job::Parse { file, fdata });
},
Job::Parse { file, fdata } => {
- let (ast, extra_data) =
- match parser::parse(fdata.tokens.get().unwrap()) {
- Ok(xs) => xs,
- Err(errs) => {
- emit_errors(&fdata, errs);
- process::exit(1)
- },
- };
+ let (ast, extra_data) = parser::parse(
+ fdata.tokens.get().unwrap(),
+ )
+ .unwrap_or_else(|errs| {
+ emit_errors(&fdata, errs);
+ process::exit(1)
+ });
if state.flags.debug_parser {
let mut handle = io::stderr().lock();
diff --git a/oryxc/src/errors.rs b/oryxc/src/errors.rs
index 71ed741..4ad88d6 100644
--- a/oryxc/src/errors.rs
+++ b/oryxc/src/errors.rs
@@ -12,7 +12,10 @@ use std::fmt::{
};
use std::io::Write;
use std::path::Path;
-use std::sync::OnceLock;
+use std::sync::{
+ LazyLock,
+ OnceLock,
+};
use std::{
env,
io,
@@ -36,12 +39,12 @@ pub enum ErrorStyle {
pub static ERROR_STYLE: OnceLock<ErrorStyle> = OnceLock::new();
pub fn progname() -> &'static OsString {
- static ARGV0: OnceLock<OsString> = OnceLock::new();
- return ARGV0.get_or_init(|| {
+ static ARGV0: LazyLock<OsString> = LazyLock::new(|| {
let default = OsStr::new("oryxc");
let s = env::args_os().next().unwrap_or(default.into());
- return Path::new(&s).file_name().unwrap_or(default).to_os_string();
+ Path::new(&s).file_name().unwrap_or(default).to_os_string()
});
+ &ARGV0
}
#[macro_export]
diff --git a/oryxc/src/main.rs b/oryxc/src/main.rs
index b5c63cf..7320c19 100644
--- a/oryxc/src/main.rs
+++ b/oryxc/src/main.rs
@@ -10,7 +10,11 @@ mod unicode;
use std::ffi::OsString;
use std::thread;
-use clap::Parser;
+use clap::{
+ CommandFactory,
+ FromArgMatches,
+ Parser,
+};
#[derive(Clone, Copy, Default)]
pub struct Flags {
@@ -38,7 +42,10 @@ struct Args {
}
fn main() {
- let args = Args::parse();
+ let args = Args::from_arg_matches(
+ &Args::command().override_usage(usage()).get_matches(),
+ )
+ .unwrap_or_else(|e| e.exit());
let threads = args.threads.unwrap_or_else(|| {
thread::available_parallelism().map_or_else(
@@ -64,3 +71,13 @@ fn main() {
let _ = errors::ERROR_STYLE.set(flags.error_style);
compiler::start(args.files, flags);
}
+
+fn usage() -> String {
+ format!(
+ concat!(
+ "Usage: {0} [-lp] [-s oneline|standard] [-t threads]\n",
+ " {0} -h",
+ ),
+ errors::progname().display()
+ )
+}