Skip to content

Commit

Permalink
Merge pull request #497 from not-my-profile/fix-blob-links
Browse files Browse the repository at this point in the history
docs: link examples & tutorial of right version on docs.rs
  • Loading branch information
zesterer authored Aug 8, 2023
2 parents 6469491 + dfec5ff commit 53bc553
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ A parser library for humans with powerful error recovery.

## Example [Brainfuck](https://en.wikipedia.org/wiki/Brainfuck) Parser

See [`examples/brainfuck.rs`](https://github.com/zesterer/chumsky/blob/master/examples/brainfuck.rs) for the full
interpreter (`cargo run --example brainfuck -- examples/sample.bf`).
See [`examples/brainfuck.rs`] for the full interpreter (`cargo run --example brainfuck -- examples/sample.bf`).

```rust
use chumsky::prelude::*;
Expand Down Expand Up @@ -73,16 +72,14 @@ fn parser<'a>() -> impl Parser<'a, &'a str, Vec<Instr>> {

Other examples include:

- A [JSON parser](https://github.com/zesterer/chumsky/blob/master/examples/json.rs) (`cargo run --example json --
examples/sample.json`)
- An [interpreter for a simple Rust-y language](https://github.com/zesterer/chumsky/blob/master/examples/nano_rust.rs)
- A [JSON parser] (`cargo run --example json -- examples/sample.json`)
- An [interpreter for a simple Rust-y language][examples/nano_rust.rs]
(`cargo run --example nano_rust -- examples/sample.nrs`)

## Tutorial

Chumsky has [a tutorial](https://github.com/zesterer/chumsky/blob/master/tutorial.md) that teaches you how to write a
parser and interpreter for a simple dynamic language with unary and binary operators, operator precedence, functions,
let declarations, and calls.
Chumsky has a [tutorial] that teaches you how to write a parser and interpreter for a simple dynamic language
with unary and binary operators, operator precedence, functions, let declarations, and calls.

## *What* is a parser combinator?

Expand Down Expand Up @@ -189,3 +186,9 @@ My apologies to Noam for choosing such an absurd name.
## License

Chumsky is licensed under the MIT license (see `LICENSE` in the main repository).

<!-- These link destinations are defined like this so that src/lib.rs can override them. -->
[`examples/brainfuck.rs`]: https://github.com/zesterer/chumsky/blob/master/examples/brainfuck.rs
[JSON parser]: https://github.com/zesterer/chumsky/blob/master/examples/json.rs
[examples/nano_rust.rs]: https://github.com/zesterer/chumsky/blob/master/examples/nano_rust.rs
[tutorial]: https://github.com/zesterer/chumsky/blob/master/tutorial.md
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
feature = "nightly",
feature(never_type, rustc_attrs, fn_traits, tuple_trait, unboxed_closures)
)]
//
// README.md links these files via the main branch. For docs.rs we however want to link them
// to the version of the documented crate since the files in the main branch may diverge.
#![doc = concat!("[`examples/brainfuck.rs`]: ", blob_url_prefix!(), "/examples/brainfuck.rs")]
#![doc = concat!("[JSON parser]: ", blob_url_prefix!(), "/examples/json.rs")]
#![doc = concat!("[examples/nano_rust.rs]: ", blob_url_prefix!(), "/examples/nano_rust.rs")]
#![doc = concat!("[tutorial]: ", blob_url_prefix!(), "/tutorial.md")]
//
#![doc = include_str!("../README.md")]
#![deny(missing_docs, clippy::undocumented_unsafe_blocks)]
#![allow(
Expand All @@ -17,6 +25,15 @@
extern crate alloc;
extern crate core;

macro_rules! blob_url_prefix {
() => {
concat!(
"https://github.com/zesterer/chumsky/blob/",
env!("CARGO_PKG_VERSION")
)
};
}

macro_rules! go_extra {
( $O :ty ) => {
#[inline(always)]
Expand Down

0 comments on commit 53bc553

Please sign in to comment.