Skip to content

Commit

Permalink
Version 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
timothee-haudebourg committed Aug 17, 2023
1 parent f906562 commit 632738e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Cargo.toml
@@ -1,7 +1,15 @@
[package]
name = "static-regular-grammar"
version = "0.1.0"
version = "1.0.0"
edition = "2021"
authors = ["Timothée Haudebourg <author@haudebourg.net>"]
categories = ["parsing"]
keywords = ["parsing", "abnf", "derive", "grammar", "regular"]
description = "Derive macro for static regular grammar"
repository = "https://github.com/timothee-haudebourg/static-regular-grammar"
documentation = "https://docs.rs/static-regular-grammar"
license = "MIT/Apache-2.0"
readme = "README.md"

[lib]
proc-macro = true
Expand Down
33 changes: 33 additions & 0 deletions README.md
Expand Up @@ -69,6 +69,20 @@ pub struct Bar([u8]);
let bar = Bar::new(b"baaaar").unwrap();
```

## ASCII

Using the `[u8]` token string type, it is possible to specify that the
value can be interpreted as an ASCII text string. Then the resulting type
will implement `Display`, `Deref<Target=str>`, `AsRef<str>`, ect.
```rust
#[derive(RegularGrammar)]
#[grammar(file = "examples/test.abnf", ascii)]
pub struct Bar([u8]);

let bar = Bar::new(b"baaaar").unwrap();
println!("{bar}");
```

## Sized Type

The `RegularGrammar` macro works on unsized type, but it is often useful
Expand Down Expand Up @@ -135,6 +149,25 @@ For large grammars, it might be a good idea to cache the automaton directly
with the sources, and ship it with your library/application to reduce
compilation time on the user machine.

## Disable automaton generation

When using a linter such as [`rust-analyzer`], it may be too expensive to
regenerate the grammar automaton continually, even with caching. On large
grammars the generated automaton code can span hundreds or even thousands
of lines. In that case it is possible to disable the automaton generation
all together using the `disable` option:
```rust
#[grammar(disable)]
```

Of course it is best to use this option behind a feature used only by the
linter:
```rust
#[cfg_attr(feature = "disable-grammars", grammar(disable))]
```

[`rust-analyzer`](https://rust-analyzer.github.io/)

<!-- cargo-rdme end -->

## License
Expand Down
34 changes: 34 additions & 0 deletions src/lib.rs
Expand Up @@ -61,6 +61,21 @@
//!
//! let bar = Bar::new(b"baaaar").unwrap();
//! ```
//!
//! # ASCII
//!
//! Using the `[u8]` token string type, it is possible to specify that the
//! value can be interpreted as an ASCII text string. Then the resulting type
//! will implement `Display`, `Deref<Target=str>`, `AsRef<str>`, ect.
//! ```
//! # use static_regular_grammar::RegularGrammar;
//! #[derive(RegularGrammar)]
//! #[grammar(file = "examples/test.abnf", ascii)]
//! pub struct Bar([u8]);
//!
//! let bar = Bar::new(b"baaaar").unwrap();
//! println!("{bar}");
//! ```
//!
//! # Sized Type
//!
Expand Down Expand Up @@ -128,6 +143,25 @@
//! For large grammars, it might be a good idea to cache the automaton directly
//! with the sources, and ship it with your library/application to reduce
//! compilation time on the user machine.
//!
//! # Disable automaton generation
//!
//! When using a linter such as [`rust-analyzer`], it may be too expensive to
//! regenerate the grammar automaton continually, even with caching. On large
//! grammars the generated automaton code can span hundreds or even thousands
//! of lines. In that case it is possible to disable the automaton generation
//! all together using the `disable` option:
//! ```ignore
//! #[grammar(disable)]
//! ```
//!
//! Of course it is best to use this option behind a feature used only by the
//! linter:
//! ```ignore
//! #[cfg_attr(feature = "disable-grammars", grammar(disable))]
//! ```
//!
//! [`rust-analyzer`](https://rust-analyzer.github.io/)
use indoc::formatdoc;
use proc_macro2::{Ident, Span, TokenStream};
use proc_macro_error::{abort, proc_macro_error};
Expand Down

0 comments on commit 632738e

Please sign in to comment.