rust skeleton

This commit is contained in:
Sebastian Hugentobler 2025-02-06 11:34:46 +01:00
parent 754713697d
commit 818816d16d
11 changed files with 710 additions and 1 deletions

29
rust/rox/src/cli.rs Normal file
View file

@ -0,0 +1,29 @@
//! Cli interface.
use std::path::PathBuf;
use clap::{Args, Parser, Subcommand};
/// Interpreter for the Lox language.
#[derive(Parser)]
#[command(version, about, long_about = None)]
#[command(propagate_version = true)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Args, Clone)]
pub struct CompileConfig {
/// Path to Lox source file.
#[arg(short, long)]
pub source: PathBuf,
}
#[derive(Subcommand)]
pub enum Commands {
/// Compile a Lox source file.
Compile(CompileConfig),
/// Run a Lox REPL.
Repl,
}

6
rust/rox/src/lib.rs Normal file
View file

@ -0,0 +1,6 @@
use std::path::Path;
pub mod cli;
pub fn compile(source: &Path) {}
pub fn repl() {}

20
rust/rox/src/main.rs Normal file
View file

@ -0,0 +1,20 @@
use clap::Parser;
use rox::cli::{Cli, Commands};
fn main() {
if std::env::var_os("RUST_LOG").is_none() {
std::env::set_var("RUST_LOG", "info");
}
tracing_subscriber::fmt::init();
let cli = Cli::parse();
match &cli.command {
Commands::Compile(compile_config) => {
rox::compile(&compile_config.source);
}
Commands::Repl => {
rox::repl();
}
}
}