summaryrefslogtreecommitdiff
path: root/oryxc/src
diff options
context:
space:
mode:
authorromir kulshrestha <romir.kulshrestha@gmail.com> 2026-03-04 18:23:43 +0100
committerromir kulshrestha <romir.kulshrestha@gmail.com> 2026-03-04 18:23:43 +0100
commitc6789ab3e29d33230da090fe7d8175d9210fa7ab (patch)
treefaeb9a91e867df04af32fb0e35050192ba488f6e /oryxc/src
parentb2daffe68f633e4ecb24caceea1b3a8f031ba6a4 (diff)
less retarded cli args
Diffstat (limited to 'oryxc/src')
-rw-r--r--oryxc/src/errors.rs3
-rw-r--r--oryxc/src/main.rs109
-rw-r--r--oryxc/src/parser.rs2
3 files changed, 37 insertions, 77 deletions
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,