Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,433 changes: 742 additions & 691 deletions vest-dsl/bitcoin/src/vest_bitcoin.rs

Large diffs are not rendered by default.

686 changes: 341 additions & 345 deletions vest-dsl/src/ast.rs

Large diffs are not rendered by default.

815 changes: 552 additions & 263 deletions vest-dsl/src/codegen.rs

Large diffs are not rendered by default.

490 changes: 315 additions & 175 deletions vest-dsl/src/elab.rs

Large diffs are not rendered by default.

11 changes: 7 additions & 4 deletions vest-dsl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ impl std::error::Error for VestError {}
/// Compiles the given source code and returns the resulting output.
///
/// # Example
/// ```rust
/// ```rust,ignore
/// use std::error::Error;
/// use std::io::Write;
/// use vest::{compile, codegen::CodegenOpts};
///
/// // build.rs
/// fn main() -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -113,10 +114,11 @@ pub fn compile(
/// Compiles the given file and returns the resulting output.
///
/// # Example
/// ```rust
/// ```rust,ignore
/// // build.rs
/// use std::error::Error;
/// use std::io::Write;
/// use vest::{compile_file, codegen::CodegenOpts};
///
/// fn main() -> Result<(), Box<dyn Error>> {
/// println!("cargo::rerun-if-changed=src/tlv.vest");
Expand All @@ -138,15 +140,16 @@ pub fn compile_file(
/// Compiles the given file and saves it to `output_file`.
///
/// # Example
/// ```rust
/// ```rust,ignore
/// // build.rs
/// use std::error::Error;
/// use vest::{compile_to, codegen::CodegenOpts};
///
/// fn main() -> Result<(), Box<dyn Error>> {
/// println!("cargo::rerun-if-changed=src/tlv.vest");
/// let input_file = "src/tlv.vest";
/// let output_file = "src/tlv.rs";
/// let code = compile_to(file_name, CodegenOpts::All, output_file)?;
/// compile_to(input_file, CodegenOpts::All, output_file)?;
/// Ok(())
/// }
/// ```
Expand Down
40 changes: 8 additions & 32 deletions vest-dsl/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use std::{error::Error, io::Write, path::PathBuf};

mod ast;
mod elab;
mod type_check;
mod utils;
mod vestir;
use std::{error::Error, path::PathBuf};

use clap::Parser;
use vest::{codegen::CodegenOpts, compile_to};

/// Vest: A generator for formally verified parsers/serializers in Verus
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -34,41 +29,22 @@ fn replace_extension(filename: &str, new_ext: &str) -> String {
path.to_string_lossy().into_owned()
}

#[derive(Debug)]
pub enum VestError {
ParsingError,
TypeError,
CodegenError,
}

impl std::fmt::Display for VestError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
VestError::ParsingError => write!(f, "Failed to compile, parsing error."),
VestError::TypeError => write!(f, "Failed to compile, type error."),
VestError::CodegenError => write!(f, "Failed to compile, codegen error."),
}
}
}

impl std::error::Error for VestError {}

fn main() -> Result<(), Box<dyn Error>> {
let args = Args::parse();

let codegen_opt = args
.codegen
.map(|s| match s.as_str() {
"all" => vest::codegen::CodegenOpts::All,
"types" => vest::codegen::CodegenOpts::Types,
"impls" => vest::codegen::CodegenOpts::Impls,
"anns" => vest::codegen::CodegenOpts::Anns,
"all" => CodegenOpts::All,
"types" => CodegenOpts::Types,
"impls" => CodegenOpts::Impls,
"anns" => CodegenOpts::Anns,
_ => panic!("Invalid codegen option"),
})
.unwrap_or(vest::codegen::CodegenOpts::All);
.unwrap_or(CodegenOpts::All);
let output_file = args
.output
.unwrap_or(replace_extension(args.vest_file.as_str(), "rs"));
vest::compile_to(&args.vest_file, codegen_opt, &output_file)?;
compile_to(&args.vest_file, codegen_opt, &output_file)?;
Ok(())
}
Loading
Loading