Update README with misses init docs and error handling note

- Rewrite Quick start to show `cargo install misses` and the new
  `misses init` subcommand as the primary entry point
- Add a dedicated `misses init` section explaining binary mode
  (build-time codegen via OUT_DIR, nothing committed) and library
  mode (--lib: generated/ committed, misses-source feature to
  rebuild, zero misses dependency for downstream users)
- Update project layout to include init.rs
- Add note that parse errors surface as compiler diagnostics via
  into_compile_error() rather than panicking

https://claude.ai/code/session_01D2g6zGJsBeUEzxBb7AvFDt
This commit is contained in:
Claude
2026-03-08 09:34:43 +00:00
parent 3be88ec21f
commit a86ba9760c
+78 -11
View File
@@ -7,22 +7,76 @@
## Quick start ## Quick start
```bash ```bash
# Build everything # Install the CLI
cargo build cargo install misses
# Run a bundled example (compare .mrs source with generated Rust) # Scaffold a new proc-macro crate (binary mode)
cargo run --example make_id_type misses init my-macros
cargo run --example derive_builder
cargo run --example derive_getters # Scaffold a library-friendly crate (generated code committed, no misses required downstream)
cargo run --example declare_table misses init --lib my-macros
cargo run --example component
# Compile a .mrs file to Rust # Compile a .mrs file to Rust
cargo run --bin misses -- path/to/my_macro.mrs > src/generated.rs misses path/to/my_macro.mrs > src/generated.rs
misses path/to/my_macro.mrs src/generated.rs
``` ```
--- ---
## `misses init` — project scaffolding
`misses init` creates a ready-to-build proc-macro crate. Two modes are available depending on whether you're shipping a binary or a library.
### Binary mode (default)
```bash
misses init my-macros
```
Use this when you control the build environment (e.g. an application binary). The `.mrs` sources are compiled to Rust at build time via `build.rs`; the generated code lives in Cargo's `$OUT_DIR` and is **never committed**.
```
my-macros/
├── Cargo.toml # misses as a plain [build-dependencies]
├── build.rs # compiles src/macros/*.mrs → $OUT_DIR/*.rs
└── src/
├── lib.rs # include!(concat!(env!("OUT_DIR"), "/hello.rs"))
└── macros/
└── hello.mrs # your macro source (committed)
```
Users only need `misses` installed to build from source, which is fine for an app you control.
### Library mode (`--lib`)
```bash
misses init --lib my-macros
```
Use this when you're publishing a library crate. Downstream users of your crate should not be forced to install misses. The generated Rust code is committed to `generated/` and shipped on crates.io.
```
my-macros/
├── Cargo.toml # misses behind [features] misses-source = ["dep:misses"]
├── build.rs # no-op unless --features misses-source
├── generated/
│ └── hello.rs # pre-generated, committed to git
└── src/
├── lib.rs # include!(concat!(env!("CARGO_MANIFEST_DIR"), "/generated/hello.rs"))
└── macros/
└── hello.mrs # your macro source (committed)
```
When you modify a `.mrs` file, regenerate with:
```bash
cargo build --features misses-source
```
The `misses-source` feature makes `misses` an optional build-dependency and gates regeneration in `build.rs`. Downstream users build normally with no misses dependency.
---
## The `.mrs` syntax ## The `.mrs` syntax
A `.mrs` file contains one or more macro definitions: A `.mrs` file contains one or more macro definitions:
@@ -137,6 +191,16 @@ macro declare_table! {
} }
``` ```
Run the bundled examples to compare `.mrs` source with generated Rust:
```bash
cargo run --example make_id_type
cargo run --example derive_builder
cargo run --example derive_getters
cargo run --example declare_table
cargo run --example component
```
--- ---
## The `misses-rt` runtime library ## The `misses-rt` runtime library
@@ -194,13 +258,14 @@ let val = kv.get("name");
``` ```
misses/ misses/
├── misses-compiler/ # The .mrs → Rust transpiler ├── misses-compiler/ # The .mrs → Rust transpiler and CLI
│ ├── src/ │ ├── src/
│ │ ├── ast.rs # Full AST types │ │ ├── ast.rs # Full AST types
│ │ ├── parser.rs # Hand-written recursive descent parser │ │ ├── parser.rs # Hand-written recursive descent parser
│ │ ├── codegen.rs # AST → Rust source string │ │ ├── codegen.rs # AST → Rust source string
│ │ ├── init.rs # `misses init` scaffolding logic
│ │ ├── lib.rs # Library API (parse + codegen) │ │ ├── lib.rs # Library API (parse + codegen)
│ │ └── main.rs # CLI binary │ │ └── main.rs # CLI binary (compile + init subcommands)
│ └── examples/ # Runnable .mrs demonstrations │ └── examples/ # Runnable .mrs demonstrations
│ ├── make_id_type.{mrs,rs} │ ├── make_id_type.{mrs,rs}
│ ├── derive_builder.{mrs,rs} │ ├── derive_builder.{mrs,rs}
@@ -226,4 +291,6 @@ For each `.mrs` macro, the compiler generates:
4. A `quote::quote! { … }` call whose body mirrors the `T~{}` template, with spread iterators for variadic bindings. 4. A `quote::quote! { … }` call whose body mirrors the `T~{}` template, with spread iterators for variadic bindings.
5. The `quote!` result is returned as `proc_macro::TokenStream`. 5. The `quote!` result is returned as `proc_macro::TokenStream`.
Parse errors are surfaced as proper Rust compiler diagnostics via `syn::Error::into_compile_error()` rather than panicking.
The generated file is formatted with [prettyplease](https://github.com/dtolnay/prettyplease) for readable output. The generated file is formatted with [prettyplease](https://github.com/dtolnay/prettyplease) for readable output.