Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update from upstream #6

Open
wants to merge 92 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
92 commits
Select commit Hold shift + click to select a range
63b4163
Begin revamp for proc-macros
Veykril Jun 27, 2021
7962cd2
Move some files around
Veykril Jun 28, 2021
c922ca3
Fix links
Veykril Jun 29, 2021
aa56ed1
General hygiene chapter
Veykril Jul 10, 2021
3424283
Fix up some book links pointing to the html files instead of the mark…
Veykril Jul 10, 2021
f9e46e7
Sort the fragment specifier listing
Veykril Jul 10, 2021
9f988bf
Change line styles in minutiae chapters
Veykril Jul 10, 2021
fac0a25
Update README
Veykril Jul 10, 2021
460b634
Fixup more line styles in src/macros
Veykril Jul 10, 2021
0cf145c
Add very sparse glossary base
Veykril Jul 10, 2021
4c4145b
Minor fixes
Veykril Jul 10, 2021
6426fb8
Make linkcheck optional
Veykril Jul 11, 2021
415561b
Fix workflow `publish_dir`
Veykril Jul 11, 2021
717e1f1
Improve the fragment specifiers chapter
Veykril Jul 13, 2021
3469e21
proc macros are a future thing
Veykril Jul 13, 2021
9b3766a
Fixes possible typo
YohannesKifle Jul 18, 2021
a6fdd6f
Hygiene blocks follow theme highlighting
Veykril Jul 21, 2021
a55add1
Add some redirects so that old links still point to the correct item
Veykril Jul 21, 2021
6ba80d8
Add quick link to bit twiddling trick in counting chapter
Veykril Jul 21, 2021
c3245a6
macro_rules macro -> declarative macro
Veykril Jul 22, 2021
55fb604
Hygenic enum counting
mbknust Jul 29, 2021
53d973e
Apply suggestions from code review
mbknust Jul 29, 2021
a7bd402
Make hyigene syntax context background more opaque on light themes
Veykril Aug 3, 2021
47532ab
proc-macros first chapter
Veykril Jul 22, 2021
25f26a9
Add third party crates section to proc-macros
Veykril Jul 22, 2021
983ee40
Restructure
Veykril Jul 23, 2021
cdb8ffe
Do a methodical <-> practical split
Veykril Jul 23, 2021
e19eb0c
Finish methodical introduction for the 3 proc-macro kinds
Veykril Jul 31, 2021
3d3acbd
proc-macro hygiene
Veykril Jul 31, 2021
f0c10d6
Split off parts of declarative macro debugging chapter into syntax ex…
Veykril Jul 31, 2021
318898e
Minor fixes, basic practical macros structure
Veykril Sep 15, 2021
82338ba
Fix hyigene link
Veykril Sep 15, 2021
e1baa14
Add const generics based counting method
GoldsteinE Sep 26, 2021
b1c37fc
Removed unnecessary word.
OLUWAMUYIWA Sep 18, 2021
9658cea
fix typo
Oct 7, 2021
ebf299e
Fold level 1 and higher in the sidebar
Veykril Oct 16, 2021
2d1801f
Change `paren` to `parenthesis` for clarity
Veykril Oct 27, 2021
6d0f8ec
Fixed typo
douweschulte Nov 13, 2021
2b3a128
Update derive.md
bestgopher Nov 25, 2021
ff4188b
Add `pat_param` fragment specifier information
Veykril Jan 2, 2022
45ca843
Add macros 2.0 chapter with syntax exploration
Veykril Jan 19, 2022
4eaec0a
Add small hygiene section for macros 2.0
Veykril Jan 19, 2022
de5ca7a
Fix typo
nmlt Feb 18, 2022
edf372e
Add note regarding push down accumulators being inherently quadratic
Veykril Mar 10, 2022
227603a
Add github sponsor button
Veykril Mar 12, 2022
7bc2778
Note that the accumulator part of push down accumulators should prefe…
Veykril Mar 12, 2022
3953024
Fix errors relating to `-Zunpretty=expanded`.
nnethercote Apr 6, 2022
e0c02fa
Update github runner OS
Veykril Apr 6, 2022
be78f40
Minor English nitpicks.
nnethercote Apr 6, 2022
42076c3
Remove incorrect sentence.
nnethercote Apr 7, 2022
8d4fe82
Document oddity of `vis` fragment in combination with `tt` fragment
Veykril Apr 7, 2022
d112f17
Add some performance advice.
nnethercote Apr 7, 2022
2f13d95
Clarify the push-down accumulator example.
nnethercote Apr 8, 2022
96514b8
Expand the vis fragment section
Veykril Apr 8, 2022
ce81d52
Link fragment specifiers from macro-rules chapter to minutiae listing
Veykril Apr 9, 2022
0f94b03
Add `Metavariable Expressions` to the macro-rules chapter
Veykril Apr 10, 2022
00fe9fc
Add metavariable expressions chapter
Veykril Apr 10, 2022
8ff8752
Move minutiae chapters out of the methodical introduction
Veykril Apr 10, 2022
7f27999
Change recursion limit number to 128
zjp-CN Apr 17, 2022
f7ef4fa
Change the captured number of `stmt` example in fragment-specifiers.md
zjp-CN Apr 17, 2022
4ee483e
Update the default edition for code blocks to 2021
zjp-CN Apr 17, 2022
7d7f727
Remove the needless whitespace
zjp-CN Apr 17, 2022
5c5332d
Fix a typo
zjp-CN Apr 17, 2022
4664803
Add missing backtick
nihaals Apr 21, 2022
244cd8e
Add Edition Differences statement for `pat`
zjp-CN Apr 18, 2022
b077c4a
Fix broken links and Add a hack example before `$$` occurs
zjp-CN Apr 18, 2022
7b7b1db
Widen the table in the practical decl macro introduction
Veykril Apr 22, 2022
d102afb
fix: Fix incorrect description of count metavar expression
Veykril May 11, 2022
bfa419d
fix grammar around 'consist'
hkBst Jun 21, 2022
0897de1
expand 'mbe'
hkBst Jun 21, 2022
b2aa1db
add missing 'as'
hkBst Jun 21, 2022
5d9ab7a
fix typos
Heinenen Jun 26, 2022
8557f4d
Add note about state of the proc-macro chapter
Veykril Sep 14, 2022
dc2ab49
Change `..., n-1, n-2` to `..., n-2, n-1`
compiler-errors Oct 11, 2022
0c25dff
n-2 comes before n-1
amab8901 Oct 12, 2022
ae96cb6
simplify the code
amab8901 Oct 12, 2022
ff7d20f
Fix tt-bundling example breaking due to 2021 edition changes
Veykril Oct 16, 2022
2b247ec
fix a typo
OccupyMars2025 May 8, 2023
0bb9ed0
fix typo
jwpjrdev May 14, 2023
4323e63
Fix typos
EduMenges Apr 7, 2023
b31bb99
Separate naive and working callback snippets
smheidrich May 13, 2023
a96b9c6
Fix C snippet
meni-adin Jun 15, 2023
7716ac0
Fix typo with inner line doc comment.
JesusGuzmanJr Aug 3, 2023
99a3c3b
Fix AST w.r.t. associativity in Source Analysis
guilliamxavier Sep 6, 2023
acd3623
Fix macro expansion in Counting # Bit twiddling
guilliamxavier Sep 6, 2023
6ef830c
Added extra 'changed' annotation in macros-practical since when readi…
David-Aguilo Jan 9, 2024
9d6fa65
Fix tests in `parsing.md`.
nnethercote Feb 7, 2024
9abe6dd
Explain how to parse methods.
nnethercote Feb 7, 2024
764adb3
Fix test failures.
nnethercote Feb 7, 2024
14eb2d7
Improve GitHub actions.
nnethercote Feb 8, 2024
768bafb
typo: expression orientated -> expression-oriented
correabuscar May 27, 2024
a70defd
`ignore` and `count` require `$ident` instead of just `ident`
correabuscar May 27, 2024
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
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[alias]
# xtask = "run --package xtask --bin xtask --"
md-test = "run --package xtask --bin xtask"
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
github: veykril
18 changes: 13 additions & 5 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
name: github pages

on:
pull_request:
push:
branches:
- master

jobs:
deploy:
runs-on: ubuntu-18.04
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Clone repository
uses: actions/checkout@v3

- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: 'latest'

- run: mdbook build
- name: Build
run: mdbook build

- name: Test
run: mdbook test

- name: Deploy
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./book
publish_dir: ./book/html
force_orphan: true
user_name: 'github-actions[bot]'
user_email: 'github-actions[bot]@users.noreply.github.com'
user_email: 'github-actions[bot]@users.noreply.github.com'
# Only deploy on a push to master, not on a pull request.
if: github.event_name == 'push' && github.ref == 'refs/heads/master' && github.repository == 'Veykril/tlborm'
3 changes: 3 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Style

Prefer a sentence-per-line format.
48 changes: 21 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,29 @@
# The Little Book of Rust Macros

> **Note**: This is a continuation of [Daniel Keep's Book](https://github.com/DanielKeep/tlborm)
> which has not been updated since the early summer of 2016, adapted to make use of
> [mdBook](https://github.com/rust-lang/mdBook).

View the [rendered version here](https://veykril.github.io/tlborm/) and the
[repository here](https://github.com/veykril/tlborm).

This book is an attempt to distill the Rust community's collective knowledge of Rust macros,
`Macros by Example` to be precise. As such, both additions (in the form of pull requests) and
requests (in the form of issues) are welcome.
The [original Little Book of Rust Macros](https://github.com/DanielKeep/tlborm) has helped me
immensely with understanding ***Macros by Example*** style macros while I was still learning the
language. Unfortunately, the author of the book has since left the project untouched, while the Rust
language as well as it's macro-system keeps evolving. Which is why I wanted to revive the project
and keep it up to date with current Rust helping other newcomers understand macros, a part of the
language a lot of people seem to have trouble with.

> This book expects you to have basic knowledge of Rust, it will not explain language features or
> constructs that are irrelevant to macros. No prior knowledge of macros is assumed. Having read and
> understood the first seven chapters of the [Rust Book](https://doc.rust-lang.org/stable/book/) is
> a must, though having read the majority of the book is recommended.
> **Note**: This is a continuation of [Daniel Keep's Book](https://github.com/DanielKeep/tlborm) which has not been updated since the early summer of 2016, adapted to make use of [mdBook](https://github.com/rust-lang/mdBook).

View the [rendered version here](https://veykril.github.io/tlborm/) and the [repository here](https://github.com/veykril/tlborm).

A chinese version of this book can be found [here](https://zjp-cn.github.io/tlborm/).

This book is an attempt to distill the Rust community's collective knowledge of Rust macros, the `Macros by Example` ones as well as procedural macros(WIP).
As such, both additions (in the form of pull requests) and requests (in the form of issues) are very much welcome.
If something's unclear, opens up questions or is not understandable as written down, fear not to make an issue asking for clarification.
The goal is for this book to become the best learning resource possible.

The [original Little Book of Rust Macros](https://github.com/DanielKeep/tlborm) has helped me immensely with understanding ***Macros by Example*** style macros while I was still learning the language.
Unfortunately, the original book hasn't been updated since April of 2016, while the Rust language as well as its macro-system keeps evolving.
Which is why I took up the task to update the book and keep it updated as well as I can while also adding newfound things to it.
In hopes that it will help out all the fresh faces coming to Rust understanding its macro systems, a part of the language a people tend to have trouble with.

> This book expects you to have basic knowledge of Rust, it will not explain language features or constructs that are irrelevant to macros.
> No prior knowledge of macros is assumed.
> Having read and understood the first seven chapters of the [Rust Book](https://doc.rust-lang.org/stable/book/) is a must, though having read the majority of the book is recommended.

## Thanks

Thanks to Daniel Keep for the original work and thanks to the following people for suggestions and
corrections to the original: IcyFoxy, Rym, TheMicroWorm, Yurume, akavel, cmr, eddyb, ogham, and
snake_case.
A big thank you to Daniel Keep for the original work as well as all the contributors that added to the original which can be found [here](https://github.com/DanielKeep/tlborm).

## License

This work inherits the licenses of the original, hence it is licensed under both the
[Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/)
and the [MIT license](http://opensource.org/licenses/MIT).
This work inherits the licenses of the original, hence it is licensed under both the [Creative Commons Attribution-ShareAlike 4.0 International License](http://creativecommons.org/licenses/by-sa/4.0/) and the [MIT license](http://opensource.org/licenses/MIT).
36 changes: 35 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,48 @@ language = "en"
multilingual = false
src = "src"
title = "The Little Book of Rust Macros"
edition = "2018"

[build]
create-missing = true
build-dir = "book"

[output.linkcheck]
traverse-parent-directories = false
optional = true

[output.html]
default-theme = "ayu"
site-url = "/tlborm/"
mathjax-support = true
git-repository-url = "https://github.com/veykril/tlborm/"
additional-css = ["res/rust-syntax-bg-highlight.css"]
additional-css = ["res/rust-syntax-bg-highlight.css"]

[output.html.fold]
enable = true
level = 1

[output.html.redirect]
"/building-blocks/abacus-counting.html" = "../decl-macros/building-blocks/abacus-counting.html"
"/building-blocks/ast-coercion.html" = "../decl-macros/building-blocks/ast-coercion.html"
"/building-blocks/counting.html" = "../decl-macros/building-blocks/counting.html"
"/building-blocks/parsing.html" = "../decl-macros/building-blocks/parsing.html"

"/macros-practical.html" = "./decl-macros/macros-practical.html"
"/patterns.html" = "./decl-macros/patterns.html"
"/building-blocks.html" = "./decl-macros/building-blocks.html"

"/patterns/callbacks.html" = "../decl-macros/patterns/callbacks.html"
"/patterns/internal-rules.html" = "../decl-macros/patterns/internal-rules.html"
"/patterns/push-down-acc.html" = "../decl-macros/patterns/push-down-acc.html"
"/patterns/repetition-placement.html" = "../decl-macros/patterns/repetition-placement.html"
"/patterns/tt-bundling.html" = "../decl-macros/patterns/tt-bundling.html"
"/patterns/tt-muncher.html" = "../decl-macros/patterns/tt-muncher.html"

"/decl-macros/syntax/ast.html" = "../../syntax-extensions/ast.html"
"/decl-macros/syntax/expansion.html" = "../../syntax-extensions/expansion.html"
"/decl-macros/syntax/source-analysis.html" = "../../syntax-extensions/source-analysis.html"

[rust]
# see: https://rust-lang.github.io/mdBook/format/configuration/general.html#rust-options
edition = "2021"
38 changes: 4 additions & 34 deletions res/rust-syntax-bg-highlight.css
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
/**
* Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
* file at the top-level directory of this distribution and at
* http://rust-lang.org/COPYRIGHT.
* With elements taken from Bootstrap v3.0.2 (MIT licensed).
*
* Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
* http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
* <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
* option. This file may not be copied, modified, or distributed
* except according to those terms.
*
* Modified by Daniel Keep.
*/


/* Code highlighting */
pre.rust .kw { color: #f92672; }
pre.rust .kw-2 { color: #f92672; }
pre.rust .prelude-ty { color: #66d9ef; }
pre.rust .number { color: #EFD6AB; }
pre.rust .string { color: #F8E9A5; }
pre.rust .self { color: #f92672; }
pre.rust .boolval { color: #EFD6AB; }
pre.rust .prelude-val { color: #66d9ef; }
pre.rust .attribute { color: #C7AFD1; }
pre.rust .attribute .ident { color: #D4BBDE; }
pre.rust .comment { color: #75715e; }
pre.rust .doccomment { color: #75715e; }
pre.rust .macro { color: #AC7FE7; }
pre.rust .macro-nonterminal { color: #CFC0E2; }
pre.rust .lifetime { color: #B76514; }
pre.rust .op { color: #f92672; }

pre.rust .synctx-0 { background-color: rgba(255, 0, 0, 0.1); }
pre.rust .synctx-1 { background-color: rgba(0, 255, 0, 0.1); }
.light pre.rust .synctx-0 { background-color: rgba(255, 0, 0, 0.2); }
.light pre.rust .synctx-1 { background-color: rgba(0, 255, 0, 0.2); }
.rust pre.rust .synctx-0 { background-color: rgba(255, 0, 0, 0.2); }
.rust pre.rust .synctx-1 { background-color: rgba(0, 255, 0, 0.2); }
73 changes: 46 additions & 27 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,49 @@

[Introduction](./introduction.md)

- [Macros, A Methodical Introduction](./macros.md)
- [Syntax Extensions](./macros/syntax.md)
- [Source Analysis](./macros/syntax/source-analysys.md)
- [Macros in the Ast](./macros/syntax/ast.md)
- [Expansion](./macros/syntax/expansion.md)
- [macro_rules!](./macros/macro_rules.md)
- [Minutiae](./macros/minutiae.md)
- [Fragment Specifiers](./macros/minutiae/fragment-specifiers.md)
- [Metavariables and Expansion Redux](./macros/minutiae/metavar-and-expansion.md)
- [Hygiene](./macros/minutiae/hygiene.md)
- [Non-Identifier Identifiers](./macros/minutiae/identifiers.md)
- [Debugging](./macros/minutiae/debugging.md)
- [Scoping](./macros/minutiae/scoping.md)
- [Import and Export](./macros/minutiae/import-export.md)
- [Macros, A Practical Introduction](./macros-practical.md)
- [Patterns](./patterns.md)
- [Callbacks](./patterns/callbacks.md)
- [Incremental TT Munchers](./patterns/tt-muncher.md)
- [Internal Rules](./patterns/internal-rules.md)
- [Push-down Accumulation](./patterns/push-down-acc.md)
- [Repetition Replacement](./patterns/repetition-replacement.md)
- [TT Bundling](./patterns/tt-bundling.md)
- [Building Blocks](./building-blocks.md)
- [AST Coercion](./building-blocks/ast-coercion.md)
- [Counting](./building-blocks/counting.md)
- [Abacus Counting](./building-blocks/abacus-counting.md)
- [Parsing Rust](./building-blocks/parsing.md)
- [Syntax Extensions](./syntax-extensions.md)
- [Source Analysis](./syntax-extensions/source-analysis.md)
- [Macros in the Ast](./syntax-extensions/ast.md)
- [Expansion](./syntax-extensions/expansion.md)
- [Hygiene](./syntax-extensions/hygiene.md)
- [Debugging](./syntax-extensions/debugging.md)
- [Declarative Macros](./decl-macros.md)
- [A Methodical Introduction](./decl-macros/macros-methodical.md)
- [A Practical Introduction](./decl-macros/macros-practical.md)
- [Minutiae](./decl-macros/minutiae.md)
- [Fragment Specifiers](./decl-macros/minutiae/fragment-specifiers.md)
- [Metavariables and Expansion Redux](./decl-macros/minutiae/metavar-and-expansion.md)
- [Metavariable Expressions](./decl-macros/minutiae/metavar-expr.md)
- [Hygiene](./decl-macros/minutiae/hygiene.md)
- [Non-Identifier Identifiers](./decl-macros/minutiae/identifiers.md)
- [Debugging](./decl-macros/minutiae/debugging.md)
- [Scoping](./decl-macros/minutiae/scoping.md)
- [Import and Export](./decl-macros/minutiae/import-export.md)
- [Patterns](./decl-macros/patterns.md)
- [Callbacks](./decl-macros/patterns/callbacks.md)
- [Incremental TT Munchers](./decl-macros/patterns/tt-muncher.md)
- [Internal Rules](./decl-macros/patterns/internal-rules.md)
- [Push-down Accumulation](./decl-macros/patterns/push-down-acc.md)
- [Repetition Replacement](./decl-macros/patterns/repetition-replacement.md)
- [TT Bundling](./decl-macros/patterns/tt-bundling.md)
- [Building Blocks](./decl-macros/building-blocks.md)
- [AST Coercion](./decl-macros/building-blocks/ast-coercion.md)
- [Counting](./decl-macros/building-blocks/counting.md)
- [Abacus Counting](./decl-macros/building-blocks/abacus-counting.md)
- [Parsing Rust](./decl-macros/building-blocks/parsing.md)
- [Macros 2.0](./decl-macros/macros2.md)
- [Procedural Macros](./proc-macros.md)
- [A Methodical Introduction](./proc-macros/methodical.md)
- [Function-like](./proc-macros/methodical/function-like.md)
- [Attribute](./proc-macros/methodical/attr.md)
- [Derive](./proc-macros/methodical/derive.md)
- [A Practical Introduction]()<!-- ./proc-macros/practical.md -->
- [Function-like]()<!-- ./proc-macros/practical/function-like.md -->
- [Attribute]()<!-- ./proc-macros/practical/attr.md -->
- [Derive]()<!-- ./proc-macros/practical/derive.md -->
- [Third-Party Crates](./proc-macros/third-party-crates.md)
- [Hygiene and Spans](./proc-macros/hygiene.md)
- [Techniques]()<!-- ./proc-macros/techniques.md -->
- [Testing]()<!-- ./proc-macros/techniques/testing.md -->

[Glossary](./glossary.md)
3 changes: 0 additions & 3 deletions src/building-blocks.md

This file was deleted.

Loading