diff --git a/README.md b/README.md index 57cfe846..4c71dc87 100644 --- a/README.md +++ b/README.md @@ -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::*; @@ -73,16 +72,14 @@ fn parser<'a>() -> impl Parser<'a, &'a str, Vec> { 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? @@ -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). + + +[`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 diff --git a/src/lib.rs b/src/lib.rs index 5ff7dc38..9d4a5869 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,6 +2,14 @@ #![cfg_attr(docsrs, feature(doc_auto_cfg, doc_cfg), deny(rustdoc::all))] #![cfg_attr(feature = "nightly", feature(never_type, rustc_attrs))] #![cfg_attr(feature = "nightly", feature(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( @@ -13,6 +21,15 @@ extern crate alloc; +macro_rules! blob_url_prefix { + () => { + concat!( + "https://github.com/zesterer/chumsky/blob/", + env!("CARGO_PKG_VERSION") + ) + }; +} + macro_rules! go_extra { ( $O :ty ) => { #[inline(always)]