feat: better clap commands
This commit is contained in:
parent
895f279be0
commit
b47030b86d
|
@ -1,10 +1,19 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::{Parser, Subcommand};
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
pub struct Cli {
|
#[clap(author, version, about, long_about = None)]
|
||||||
pub input: PathBuf,
|
#[clap(propagate_version = true)]
|
||||||
|
pub enum Cli {
|
||||||
|
#[clap(subcommand)]
|
||||||
|
Uplc(UplcCommand),
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand)]
|
||||||
|
pub enum UplcCommand {
|
||||||
|
Flat { input: PathBuf },
|
||||||
|
Unflat { input: PathBuf },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Cli {
|
impl Default for Cli {
|
||||||
|
|
|
@ -1,59 +1,45 @@
|
||||||
use uplc::{
|
use uplc::{
|
||||||
ast::{DeBruijn, NamedDeBruijn, Program},
|
ast::{DeBruijn, FakeNamedDeBruijn, Program},
|
||||||
parser,
|
parser,
|
||||||
};
|
};
|
||||||
|
|
||||||
use neptune::Cli;
|
use neptune::{Cli, UplcCommand};
|
||||||
|
|
||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
let args = Cli::default();
|
let args = Cli::default();
|
||||||
|
|
||||||
let code = std::fs::read_to_string(&args.input)?;
|
match args {
|
||||||
|
Cli::Uplc(uplc) => match uplc {
|
||||||
|
UplcCommand::Flat { input } => {
|
||||||
|
let code = std::fs::read_to_string(&input)?;
|
||||||
|
|
||||||
let program = parser::program(&code)?;
|
let program = parser::program(&code)?;
|
||||||
|
|
||||||
println!("\nName:");
|
let program = Program::<DeBruijn>::try_from(program)?;
|
||||||
println!("{:#?}", program);
|
|
||||||
|
|
||||||
let flat_bytes = program.to_flat()?;
|
let bytes = program.to_flat()?;
|
||||||
|
|
||||||
print!("\nflat bits:\n");
|
for (i, byte) in bytes.iter().enumerate() {
|
||||||
|
print!("{:08b}", byte);
|
||||||
|
|
||||||
for byte in flat_bytes {
|
if (i + 1) % 4 == 0 {
|
||||||
print!("{:08b} ", byte);
|
println!();
|
||||||
|
} else {
|
||||||
|
print!(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!();
|
||||||
|
}
|
||||||
|
UplcCommand::Unflat { input } => {
|
||||||
|
let bytes = std::fs::read(&input)?;
|
||||||
|
|
||||||
|
let program = Program::<FakeNamedDeBruijn>::from_flat(&bytes)?;
|
||||||
|
|
||||||
|
println!("{:#?}", program);
|
||||||
|
}
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
println!();
|
|
||||||
|
|
||||||
let program_nd: Program<NamedDeBruijn> = program.try_into()?;
|
|
||||||
|
|
||||||
println!("\nNamed De Bruijn:");
|
|
||||||
println!("{:#?}", program_nd);
|
|
||||||
|
|
||||||
let flat_bytes = program_nd.to_flat()?;
|
|
||||||
|
|
||||||
print!("\nflat bits:\n");
|
|
||||||
|
|
||||||
for byte in flat_bytes {
|
|
||||||
print!("{:08b} ", byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!();
|
|
||||||
|
|
||||||
let program_d: Program<DeBruijn> = program_nd.into();
|
|
||||||
|
|
||||||
println!("\nDe Bruijn:");
|
|
||||||
println!("{:#?}", program_d);
|
|
||||||
|
|
||||||
let flat_bytes = program_d.to_flat()?;
|
|
||||||
|
|
||||||
print!("\nflat bits:\n");
|
|
||||||
|
|
||||||
for byte in flat_bytes {
|
|
||||||
print!("{:08b} ", byte);
|
|
||||||
}
|
|
||||||
|
|
||||||
println!();
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
(program 11.22.33
|
(program 11.22.33
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
lam x (lam x y)) (con string "PT8"
|
lam x (lam x x)) (con string "PT8"
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
)
|
Loading…
Reference in New Issue