summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock139
-rw-r--r--oryxc/Cargo.toml2
-rw-r--r--oryxc/src/errors.rs3
-rw-r--r--oryxc/src/main.rs106
4 files changed, 71 insertions, 179 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 9c206b2..cfe485b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -20,56 +20,6 @@ dependencies = [
]
[[package]]
-name = "anstream"
-version = "0.6.21"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
-dependencies = [
- "anstyle",
- "anstyle-parse",
- "anstyle-query",
- "anstyle-wincon",
- "colorchoice",
- "is_terminal_polyfill",
- "utf8parse",
-]
-
-[[package]]
-name = "anstyle"
-version = "1.0.13"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5192cca8006f1fd4f7237516f40fa183bb07f8fbdfedaa0036de5ea9b0b45e78"
-
-[[package]]
-name = "anstyle-parse"
-version = "0.2.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
-dependencies = [
- "utf8parse",
-]
-
-[[package]]
-name = "anstyle-query"
-version = "1.1.5"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
-dependencies = [
- "windows-sys 0.61.2",
-]
-
-[[package]]
-name = "anstyle-wincon"
-version = "3.0.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
-dependencies = [
- "anstyle",
- "once_cell_polyfill",
- "windows-sys 0.61.2",
-]
-
-[[package]]
name = "anyhow"
version = "1.0.102"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -152,52 +102,6 @@ dependencies = [
]
[[package]]
-name = "clap"
-version = "4.5.60"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2797f34da339ce31042b27d23607e051786132987f595b02ba4f6a6dffb7030a"
-dependencies = [
- "clap_builder",
- "clap_derive",
-]
-
-[[package]]
-name = "clap_builder"
-version = "4.5.60"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "24a241312cea5059b13574bb9b3861cabf758b879c15190b37b6d6fd63ab6876"
-dependencies = [
- "anstream",
- "anstyle",
- "clap_lex",
- "strsim",
-]
-
-[[package]]
-name = "clap_derive"
-version = "4.5.55"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a92793da1a46a5f2a02a6f4c46c6496b28c43638adea8306fcb0caa1634f24e5"
-dependencies = [
- "heck",
- "proc-macro2",
- "quote",
- "syn",
-]
-
-[[package]]
-name = "clap_lex"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3a822ea5bc7590f9d40f1ba12c0dc3c2760f3482c6984db1573ad11031420831"
-
-[[package]]
-name = "colorchoice"
-version = "1.0.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
-
-[[package]]
name = "constant_time_eq"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -459,12 +363,6 @@ dependencies = [
]
[[package]]
-name = "is_terminal_polyfill"
-version = "1.70.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
-
-[[package]]
name = "itoa"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -497,6 +395,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2"
[[package]]
+name = "lexopt"
+version = "0.3.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "803ec87c9cfb29b9d2633f20cba1f488db3fd53f2158b1024cbefb47ba05d413"
+
+[[package]]
name = "libbz2-rs-sys"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -561,19 +465,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
-name = "once_cell_polyfill"
-version = "1.70.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
-
-[[package]]
name = "oryxc"
version = "0.1.0"
dependencies = [
"boxcar",
- "clap",
"crossbeam-deque",
"dashmap",
+ "lexopt",
"phf",
"soa-rs",
"unicode-normalization",
@@ -732,7 +630,7 @@ dependencies = [
"getrandom 0.2.17",
"libc",
"untrusted",
- "windows-sys 0.52.0",
+ "windows-sys",
]
[[package]]
@@ -897,12 +795,6 @@ dependencies = [
]
[[package]]
-name = "strsim"
-version = "0.11.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
-
-[[package]]
name = "subtle"
version = "2.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1035,12 +927,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9"
[[package]]
-name = "utf8parse"
-version = "0.2.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
-
-[[package]]
name = "version_check"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1174,15 +1060,6 @@ dependencies = [
]
[[package]]
-name = "windows-sys"
-version = "0.61.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
-dependencies = [
- "windows-link",
-]
-
-[[package]]
name = "windows-targets"
version = "0.52.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/oryxc/Cargo.toml b/oryxc/Cargo.toml
index 4230086..23ae95b 100644
--- a/oryxc/Cargo.toml
+++ b/oryxc/Cargo.toml
@@ -5,9 +5,9 @@ edition = "2024"
[dependencies]
boxcar = "0.2.14"
-clap = { version = "4", features = ["derive"] }
crossbeam-deque = "0.8.6"
dashmap = "6.1.0"
+lexopt = "0.3.2"
phf = { version = "0.13.1", features = ["macros"] }
soa-rs = "0.9.1"
unicode-normalization = "0.1.25"
diff --git a/oryxc/src/errors.rs b/oryxc/src/errors.rs
index 4ad88d6..2c8f268 100644
--- a/oryxc/src/errors.rs
+++ b/oryxc/src/errors.rs
@@ -28,9 +28,8 @@ use crate::unicode;
const TAB_AS_SPACES: &'static str = " ";
const TABSIZE: usize = TAB_AS_SPACES.len();
-#[derive(Clone, Copy, Default, Eq, PartialEq, clap::ValueEnum)]
+#[derive(Clone, Copy, Default, Eq, PartialEq)]
pub enum ErrorStyle {
- #[value(name = "oneline")]
OneLine,
#[default]
Standard,
diff --git a/oryxc/src/main.rs b/oryxc/src/main.rs
index 8d38ab1..d46648f 100644
--- a/oryxc/src/main.rs
+++ b/oryxc/src/main.rs
@@ -10,77 +10,93 @@ mod size;
mod unicode;
mod unistr;
+use std::borrow::Cow;
+use std::env;
use std::ffi::OsString;
+use std::process;
use std::thread;
-use clap::{
- CommandFactory,
- FromArgMatches,
- Parser,
-};
+use lexopt;
#[derive(Clone, Copy, Default)]
pub struct Flags {
pub debug_lexer: bool,
pub debug_parser: bool,
- pub threads: usize,
pub error_style: errors::ErrorStyle,
+ pub threads: usize,
}
-#[derive(Parser)]
-struct Args {
- #[arg(long)]
- debug_lexer: bool,
+impl Flags {
+ fn parse() -> Result<(Flags, Vec<OsString>), lexopt::Error> {
+ use lexopt::prelude::*;
- #[arg(long)]
- debug_parser: bool,
+ let mut rest = Vec::with_capacity(env::args().len());
+ let mut flags = Flags::default();
+ let mut parser = lexopt::Parser::from_env();
+ parser.set_short_equals(false);
- #[arg(short = 's', long, default_value = "standard")]
- error_style: errors::ErrorStyle,
+ while let Some(arg) = parser.next()? {
+ match arg {
+ Short('h') | Long("help") => usage(0),
+ Short('l') | Long("debug-lexer") => flags.debug_lexer = true,
+ Short('p') | Long("debug-parser") => flags.debug_parser = true,
+ Short('s') | Long("error-style") => {
+ flags.error_style = match parser.value()?.to_string_lossy()
+ {
+ Cow::Borrowed("oneline") => errors::ErrorStyle::OneLine,
+ Cow::Borrowed("standard") => {
+ errors::ErrorStyle::Standard
+ },
+ s => Err(format!(
+ "{s}: invalid value for -s/--error-style"
+ ))?,
+ };
+ },
+ Short('t') | Long("threads") => {
+ flags.threads = parser.value()?.parse()?;
+ if flags.threads == 0 {
+ err!("thread count must be greater than 0");
+ }
+ },
+ Value(v) => rest.push(v),
+ _ => return Err(arg.unexpected()),
+ }
+ }
- #[arg(short = 't', long)]
- threads: Option<usize>,
+ if flags.threads == 0 {
+ flags.threads = thread::available_parallelism().map_or_else(
+ |e| {
+ warn!(e, "failed to get thread count");
+ 1
+ },
+ |x| x.get(),
+ );
+ }
- files: Vec<OsString>,
+ return Ok((flags, rest));
+ }
}
fn main() {
- 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(
- |e| {
- warn!(e, "failed to get thread count");
- 1
- },
- |x| x.get(),
- )
- });
-
- if threads == 0 {
- err!("thread count must be greater than 0");
- }
-
- let flags = Flags {
- debug_lexer: args.debug_lexer,
- debug_parser: args.debug_parser,
- threads,
- error_style: args.error_style,
+ let (flags, rest) = match Flags::parse() {
+ Ok(v) => v,
+ Err(e) => {
+ warn!(e);
+ usage(1);
+ },
};
let _ = errors::ERROR_STYLE.set(flags.error_style);
- compiler::start(args.files, flags);
+ compiler::start(rest, flags);
}
-fn usage() -> String {
- format!(
+fn usage(n: i32) -> ! {
+ eprintln!(
concat!(
"Usage: {0} [-s oneline|standard] [-t threads]\n",
" {0} -h",
),
errors::progname().display()
- )
+ );
+ process::exit(n);
}