diff options
| -rw-r--r-- | Cargo.lock | 137 | ||||
| -rw-r--r-- | oryxc/Cargo.toml | 2 | ||||
| -rw-r--r-- | oryxc/src/errors.rs | 3 | ||||
| -rw-r--r-- | oryxc/src/main.rs | 109 | ||||
| -rw-r--r-- | oryxc/src/parser.rs | 2 |
5 files changed, 174 insertions, 79 deletions
@@ -3,6 +3,56 @@ version = 4 [[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", +] + +[[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", +] + +[[package]] name = "bitflags" version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -15,6 +65,52 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" [[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 = "crossbeam-deque" version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -66,6 +162,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "is_terminal_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" + +[[package]] name = "lexopt" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -93,12 +201,18 @@ 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 = "oryx" version = "0.1.0" dependencies = [ + "clap", "crossbeam-deque", "dashmap", - "lexopt", "phf", "soa-rs", "unicode-width", @@ -255,6 +369,12 @@ dependencies = [ ] [[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] name = "syn" version = "2.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -285,7 +405,22 @@ dependencies = [ ] [[package]] +name = "utf8parse" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" + +[[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] diff --git a/oryxc/Cargo.toml b/oryxc/Cargo.toml index 1b418f3..4308b1a 100644 --- a/oryxc/Cargo.toml +++ b/oryxc/Cargo.toml @@ -7,7 +7,7 @@ edition = "2024" crossbeam-deque = "0.8.6" dashmap = "6.1.0" # icu = { version = "2.1.1", features = ["compiled_data"] } -lexopt = "0.3.2" +clap = { version = "4", features = ["derive"] } # num-rational = "0.4.2" phf = { version = "0.13.1", features = ["macros"] } soa-rs = "0.9.1" diff --git a/oryxc/src/errors.rs b/oryxc/src/errors.rs index 290abc2..71ed741 100644 --- a/oryxc/src/errors.rs +++ b/oryxc/src/errors.rs @@ -25,8 +25,9 @@ use crate::unicode; const TAB_AS_SPACES: &'static str = " "; const TABSIZE: usize = TAB_AS_SPACES.len(); -#[derive(Clone, Copy, Default, Eq, PartialEq)] +#[derive(Clone, Copy, Default, Eq, PartialEq, clap::ValueEnum)] pub enum ErrorStyle { + #[value(name = "oneline")] OneLine, #[default] Standard, diff --git a/oryxc/src/main.rs b/oryxc/src/main.rs index 7a0b0a8..ed7c550 100644 --- a/oryxc/src/main.rs +++ b/oryxc/src/main.rs @@ -7,101 +7,60 @@ mod parser; mod size; mod unicode; -use std::borrow::Cow; use std::ffi::OsString; -use std::{ - env, - process, - thread, -}; +use std::thread; -use lexopt; +use clap::Parser; #[derive(Clone, Copy, Default)] pub struct Flags { pub debug_lexer: bool, pub debug_parser: bool, - pub help: bool, pub threads: usize, pub error_style: errors::ErrorStyle, } -impl Flags { - fn parse() -> Result<(Flags, Vec<OsString>), lexopt::Error> { - use lexopt::prelude::*; +#[derive(Parser)] +struct Args { + #[arg(short = 'l', long)] + debug_lexer: 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 = 'p', long)] + debug_parser: bool, - while let Some(arg) = parser.next()? { - match arg { - 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") => { - 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 = 's', long, default_value = "standard")] + error_style: errors::ErrorStyle, - if flags.threads == 0 { - flags.threads = thread::available_parallelism().map_or_else( - |e| { - warn!(e, "failed to get thread count"); - 1 - }, - |x| x.get(), - ); - } + #[arg(short = 't', long)] + threads: Option<usize>, - return Ok((flags, rest)); - } -} - -fn usage() { - eprintln!( - concat!( - "Usage: {0} [-lp] [-s oneline|standard] [-t threads]\n", - " {0} -h", - ), - errors::progname().display() - ); + files: Vec<OsString>, } fn main() { - let (flags, rest) = match Flags::parse() { - Ok(v) => v, - Err(e) => { - warn!(e); - usage(); - process::exit(1); - }, - }; + let args = Args::parse(); - if flags.help { - usage(); - process::exit(0); + 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 _ = errors::ERROR_STYLE.set(flags.error_style); - compiler::start(rest, flags); + compiler::start(args.files, flags); } diff --git a/oryxc/src/parser.rs b/oryxc/src/parser.rs index a623d3e..193428b 100644 --- a/oryxc/src/parser.rs +++ b/oryxc/src/parser.rs @@ -825,7 +825,7 @@ impl<'a> Parser<'a> { p.extra_data.push(*x); } /* FIXME: Missing LHS, and doesn’t conform to the - * description at the definition of AstType */ + * description at the definition of AstType */ return Ok(p.new_node(AstNode { kind: AstType::FunCall, tok, |