feat: lexer

This commit is contained in:
rvcas
2022-08-12 19:44:34 -04:00
parent 208f2e80ea
commit 1d6809661c
13 changed files with 1414 additions and 37 deletions

View File

@@ -7,6 +7,15 @@ use clap::{Parser, Subcommand};
#[clap(version, about, long_about = None)]
#[clap(propagate_version = true)]
pub enum Args {
/// Build an aiken project
Build,
/// Start a development server
Dev,
/// Create a new aiken project
New {
/// Project name
name: PathBuf,
},
/// A subcommand for working with Untyped Plutus Core
#[clap(subcommand)]
Uplc(UplcCommand),
@@ -15,33 +24,49 @@ pub enum Args {
/// Commands for working with Untyped Plutus Core
#[derive(Subcommand)]
pub enum UplcCommand {
/// Evaluate an Untyped Plutus Core program
Eval {
/// Handle input as flat bytes
#[clap(short, long)]
flat: bool,
/// File to load and evaluate
input: PathBuf,
},
/// Encode textual Untyped Plutus Core to flat bytes
Flat {
/// Textual Untyped Plutus Core file
input: PathBuf,
#[clap(short, long)]
print: bool,
/// Output file name
#[clap(short, long)]
out: Option<String>,
},
/// Decode flat bytes to textual Untyped Plutus Core
Unflat {
input: PathBuf,
/// Print output instead of saving to file
#[clap(short, long)]
print: bool,
#[clap(short, long)]
out: Option<String>,
},
/// Format an Untyped Plutus Core program
Fmt {
/// Textual Untyped Plutus Core file
input: PathBuf,
/// Print output instead of saving to file
#[clap(short, long)]
print: bool,
},
/// Evaluate an Untyped Plutus Core program
Eval {
/// Decode flat bytes to textual Untyped Plutus Core
Unflat {
/// Flat encoded Untyped Plutus Core file
input: PathBuf,
/// Output file name
#[clap(short, long)]
flat: bool,
out: Option<String>,
/// Print output instead of saving to file
#[clap(short, long)]
print: bool,
},
}

View File

@@ -14,6 +14,31 @@ fn main() -> anyhow::Result<()> {
let args = Args::default();
match args {
Args::Build => {
// 1. load and parse modules
// * lib - contains modules, types, and functions
// * contracts - contains validators
// * scripts - contains native scripts dsl
// 2. type check everything
// 3. generate uplc and policy/address if relevant
todo!()
}
Args::Dev => {
// launch a development server
// this should allow people to test
// their contracts over http
todo!()
}
Args::New { name } => {
if !name.exists() {
fs::create_dir_all(name.join("lib"))?;
fs::create_dir_all(name.join("policies"))?;
fs::create_dir_all(name.join("scripts"))?;
}
}
Args::Uplc(uplc) => match uplc {
UplcCommand::Flat { input, print, out } => {
let code = std::fs::read_to_string(&input)?;
@@ -48,6 +73,7 @@ fn main() -> anyhow::Result<()> {
fs::write(&out_name, &bytes)?;
}
}
UplcCommand::Fmt { input, print } => {
let code = std::fs::read_to_string(&input)?;
@@ -61,6 +87,7 @@ fn main() -> anyhow::Result<()> {
fs::write(&input, pretty)?;
}
}
UplcCommand::Unflat { input, print, out } => {
let bytes = std::fs::read(&input)?;
@@ -82,6 +109,7 @@ fn main() -> anyhow::Result<()> {
fs::write(&out_name, pretty)?;
}
}
UplcCommand::Eval { input, flat } => {
let program = if flat {
let bytes = std::fs::read(&input)?;