diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 5be0bd5153..bbeb1dd52b 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -107,6 +107,23 @@ jobs:
working-directory: ./xtask
run: cargo fmt --check
+ reference-dev-guide:
+ name: reference-dev-guide build check
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@master
+ - name: Install mdbook
+ env:
+ MDBOOK_VERSION: 0.5.1
+ run: |
+ mkdir bin
+ curl -sSL https://github.com/rust-lang/mdBook/releases/download/v${MDBOOK_VERSION}/mdbook-v${MDBOOK_VERSION}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=bin
+ echo "$(pwd)/bin" >> $GITHUB_PATH
+ - name: Check reference-dev-guide build
+ run: |
+ cd reference-dev-guide
+ mdbook build
+
preview:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
@@ -153,6 +170,7 @@ jobs:
- code-tests
- style-tests
- mdbook-spec
+ - reference-dev-guide
# preview is explicitly excluded here since it doesn't run on merge
runs-on: ubuntu-latest
steps:
diff --git a/.github/workflows/reference-dev-guide.yml b/.github/workflows/reference-dev-guide.yml
new file mode 100644
index 0000000000..6007693f11
--- /dev/null
+++ b/.github/workflows/reference-dev-guide.yml
@@ -0,0 +1,49 @@
+name: Deploy reference-dev-guide
+on:
+ push:
+ branches:
+ - master
+
+env:
+ MDBOOK_VERSION: 0.5.1
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v6
+
+ - name: Install mdbook
+ run: |
+ mkdir mdbook
+ curl -Lf https://github.com/rust-lang/mdBook/releases/download/v${{ env.MDBOOK_VERSION }}/mdbook-v${{ env.MDBOOK_VERSION }}-x86_64-unknown-linux-gnu.tar.gz | tar -xz --directory=./mdbook
+ echo `pwd`/mdbook >> $GITHUB_PATH
+
+ - name: Build the book
+ run: |
+ cd reference-dev-guide
+ mdbook build
+ mkdir out
+ touch out/.nojekyll
+ mv book out/reference-dev-guide
+
+ - name: Upload Artifact
+ uses: actions/upload-pages-artifact@v3
+ with:
+ path: ./reference-dev-guide/out
+
+ deploy:
+ needs: build
+
+ permissions:
+ pages: write
+ id-token: write
+
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+
+ runs-on: ubuntu-latest
+ steps:
+ - id: deployment
+ uses: actions/deploy-pages@v4
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index cc2acb9767..6edf2913c5 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,76 +1,3 @@
-Thank you for your interest in contributing to the Rust Reference!
+# Contributing to The Rust Reference
-There are a few ways of helping with the reference: critiquing the reference,
-editing the reference, fixing incorrect information, adding examples and
-glossary entries, and documenting new or otherwise undocumented features in
-Rust.
-
-For a while, the Reference was basically ignored, and Rust continued gaining new
-features or changing old ones. It was also basically the introduction document
-before the first edition of the Rust book, and constantly in flux from the huge
-churn of the language design before v1.0.0. So there's a lot that's wrong, too
-teachy for people who should have basic understanding of Rust, or is too shallow
-for the Reference. As such, we have the warning saying there's work that needs
-to be done. Eventually, we plan to make sure everything is well documented
-enough that we can remove the warning.
-
-It is encouraged for you to read the [introduction] to familiarize yourself with
-the kind of content the reference is expected to contain and the conventions it
-uses. Also, the [Authoring Guide] provides more detailed guidelines for
-formatting and content.
-
-## Critiquing the Reference
-
-This is the easiest way to contribute. Basically, as you read the reference, if
-you find something confusing, incorrect, or missing, then you can file an issue
-against the reference explaining your concerns.
-
-## Editing the Reference
-
-Typos and incorrect links get through from time to time. Should you find them,
-we welcome PRs to fix them. Additionally, larger editing jobs that help remove
-the number of parentheticals, remove comma splices, italicize term definitions
-and other similar tasks are helpful.
-
-## Adding examples and glossary entries
-
-Examples are great. Many people will only read examples and ignore the prose.
-Ideally, every facet of every feature will have an example.
-
-Likewise, the reference has a glossary. It doesn't need to explain every facet
-of every feature nor contain every definition, but it does need to be expanded
-upon. Ideally entries in the glossary link to the associated documentation.
-
-## Adding documentation
-
-There are a lot of features that are not documented at all or are documented
-poorly. This is the hardest, but definitely most valuable. Pick an unassigned
-issue from the [issue tracker], and write about it.
-
-While writing, you may find it handy to have a [playpen] open to test out what
-you are documenting.
-
-Feel free to take information from the standard library and Rustonomicon as
-appropriate.
-
-Note that we don't write documentation for purely library features such as
-threads and IO and we don't write about Rust in the future. Documentation is
-written as if the current stable release of Rust is the last release. The
-`master` branch of the reference corresponds to what is **stable** on the
-`master` branch ("nightly") of [rust-lang/rust]. If you want to write about
-Rust in the future, you want [the Unstable book][unstable].
-
-## Stabilization
-
-When something that alters the language is stabilized, an issue should be
-opened on the reference [issue tracker] to track the documentation process.
-This should include links to any relevant information, such as the
-stabilization PR, the RFC, the tracking issue, and anything else that would be
-helpful for writing the documentation.
-
-[Authoring Guide]: docs/authoring.md
-[introduction]: src/introduction.md
-[issue tracker]: https://github.com/rust-lang/reference/issues
-[playpen]: https://play.rust-lang.org/
-[rust-lang/rust]: https://github.com/rust-lang/rust/
-[unstable]: https://doc.rust-lang.org/nightly/unstable-book/
+See the [Reference Developer Guide](https://rust-lang.github.io/reference/reference-dev-guide/) for information on contributing to the Reference.
diff --git a/README.md b/README.md
index 1db891c78f..a06d5c10da 100644
--- a/README.md
+++ b/README.md
@@ -4,91 +4,4 @@ This document is the primary reference for the Rust programming language.
## Contributor docs
-There are several pages for those working on the reference:
-
-* [Authoring guide](https://github.com/rust-lang/reference/blob/master/docs/authoring.md): Guidelines for writing content.
-* [Review policy](https://github.com/rust-lang/reference/blob/master/docs/review-policy.md): Guidelines for reviewers.
-* [Grammar](https://github.com/rust-lang/reference/blob/master/docs/grammar.md): How the grammar syntax works.
-* [Attribute template](https://github.com/rust-lang/reference/blob/master/docs/attribute-template.md): The standard template for documenting an attribute.
-
-## Building
-
-To build the Reference, first clone the project:
-
-```sh
-git clone https://github.com/rust-lang/reference.git
-cd reference
-```
-
-(Alternatively, if you don't want to use `git`, [download][] a ZIP file
-of the project, extract it using your preferred tool, and rename the
-top-level directory to `reference`.)
-
-[download]: https://github.com/rust-lang/reference/archive/refs/heads/master.zip
-
-### Installing mdbook
-
-The Reference is built using [mdbook].
-
-First, ensure that you have a recent copy of the nightly Rust compiler installed, as this is needed in order to run the tests:
-
-```sh
-rustup toolchain install nightly
-rustup override set nightly
-```
-
-Now, ensure you have `mdbook` installed, as this is needed in order to build the Reference:
-
-```sh
-cargo install --locked mdbook
-```
-
-[mdbook]: https://rust-lang.github.io/mdBook/
-
-### Running mdbook
-
-`mdbook` provides a variety of different commands and options to help you work on the book:
-
-* `mdbook build --open`: Build the book and open it in a web browser.
-* `mdbook serve --open`: Launches a web server on localhost. It also automatically rebuilds the book whenever any file changes and automatically reloads your web browser.
-
-The book contents are driven by a `SUMMARY.md` file, and every file must be linked there. See for its usage.
-
-### `SPEC_RELATIVE`
-
-The `SPEC_RELATIVE=0` environment variable makes links to the standard library go to instead of being relative, which is useful when viewing locally since you normally don't have a copy of the standard library.
-
-```sh
-SPEC_RELATIVE=0 mdbook serve --open
-```
-
-The published site at (or local docs using `rustup doc`) does not set this, which means it will use relative links which supports offline viewing and links to the correct version (for example, links in will stay within the 1.81.0 directory).
-
-### `SPEC_DENY_WARNINGS`
-
-The `SPEC_DENY_WARNINGS=1` environment variable will turn all warnings generated by `mdbook-spec` to errors. This is used in CI to ensure that there aren't any problems with the book content.
-
-### `SPEC_RUST_ROOT`
-
-The `SPEC_RUST_ROOT` can be used to point to the directory of a checkout of . This is used by the test-linking feature so that it can find tests linked to reference rules. If this is not set, then the tests won't be linked.
-
-## Running tests
-
-There are several different kinds of tests you can run (these are enforced on CI):
-
-* `mdbook test`: This will run the inline Rust codeblocks (internally it uses `rustdoc` to do this).
-* `cargo xtask style-check`: This will validate some style checks (see [authoring guide](docs/authoring.md)).
-* `cargo xtask linkcheck`: This will validate that markdown links aren't broken.
-* `cargo xtask test-all`: Runs all tests.
-
-## How is this published?
-
-The process for getting the reference content into a [Rust release](https://doc.rust-lang.org/reference/#rust-releases) and on the website is:
-
-1. Changes are merged to this repository.
-2. [Triagebot](https://forge.rust-lang.org/triagebot/doc-updates.html) will automatically synchronize this repository to [rust-lang/rust]. This happens every other week. The reference is tracked in [rust-lang/rust] as a [submodule](https://github.com/rust-lang/rust/tree/master/src/doc).
- - This will open a PR on [rust-lang/rust] which needs to be merged, and that can take up to several days.
-3. At midnight UTC, whatever is on the default branch of [rust-lang/rust] will be a part of that nightly release, and will be published after a few hours to .
-4. Following Rust's [release process](https://doc.rust-lang.org/book/appendix-07-nightly-rust.html), every 6 weeks, nightly will be promoted to beta (), and then 6 weeks after that it will be promoted to stable ().
-
-[rust-lang/rust]: https://github.com/rust-lang/rust/
+See the [Reference Developer Guide](https://rust-lang.github.io/reference/reference-dev-guide/) for information on contributing to the Reference.
diff --git a/STYLE.md b/STYLE.md
deleted file mode 100644
index 5a64884615..0000000000
--- a/STYLE.md
+++ /dev/null
@@ -1,5 +0,0 @@
-# Rust reference style guide
-
-See the [Authoring Guide] for details on the style used in the reference.
-
-[Authoring Guide]: docs/authoring.md
diff --git a/docs/authoring.md b/docs/authoring.md
index 1d09bb2fe2..f23b8b79b2 100644
--- a/docs/authoring.md
+++ b/docs/authoring.md
@@ -4,203 +4,6 @@ This document serves as a guide for editors and reviewers. Some conventions and
[introduction]: ../src/introduction.md
-## Markdown formatting
-
-* Use [ATX-style headings][atx] (not Setext) with [sentence case].
-* Do not use tabs, only spaces.
-* Files must end with a newline.
-* Lines must not end with spaces. Double spaces have semantic meaning, but can be invisible. Use a trailing backslash if you need a hard line break.
-* If possible, avoid double blank lines.
-* Do not use indented code blocks; use 3+ backticks code blocks instead.
-* Code blocks should have an explicit language tag.
-* Do not wrap long lines. This helps with reviewing diffs of the source.
-* Use [smart punctuation] instead of Unicode characters. For example, use `---` for em-dash instead of the Unicode character. Characters like em-dash can be difficult to see in a fixed-width editor, and some editors may not have easy methods to enter such characters.
-* Links should be relative with the `.md` extension. Links to other rust-lang books that are published with the reference should also be relative so that the linkchecker can validate them.
-* Links to the standard library should use rustdoc-style links described in [Standard library links](#standard-library-links).
-* The use of reference links is preferred, with shortcuts if appropriate. Place the sorted link reference definitions at the bottom of the file, or at the bottom of a section if there are an unusually large number of links that are specific to the section.
-
- ```markdown
- Example of shortcut link: [enumerations]
- Example of reference link with label: [block expression][block]
-
- [block]: expressions/block-expr.md
- [enumerations]: types/enum.md
- ```
-* See the [Conventions] section for formatting callouts such as notes, edition differences, and warnings.
-
-There are automated checks for some of these rules. Run `cargo xtask style-check` to run them locally.
-
-[atx]: https://spec.commonmark.org/0.31.2/#atx-headings
-[conventions]: ../src/introduction.md#conventions
-[sentence case]: https://apastyle.apa.org/style-grammar-guidelines/capitalization/sentence-case
-[smart punctuation]: https://rust-lang.github.io/mdBook/format/markdown.html#smart-punctuation
-
-### Code examples
-
-Code examples should use code blocks with triple backticks. The language should always be specified (such as `rust`).
-
-```rust
-println!("Hello!");
-```
-
-See for a list of supported languages.
-
-Rust examples are tested via rustdoc, and should include the appropriate annotations:
-
-* `edition2015`, `edition2018`, etc. --- If it is edition-specific (see `book.toml` for the default).
-* `no_run` --- The example should compile successfully, but should not be executed.
-* `should_panic` --- The example should compile and run, but produce a panic.
-* `compile_fail` --- The example is expected to fail to compile.
-* `ignore` --- The example shouldn't be built or tested. This should be avoided if possible. Usually this is only necessary when the testing framework does not support it (such as external crates or modules, or a proc-macro), or it contains pseudo-code which is not valid Rust. An HTML comment such as `` should be placed before the example to explain why it is ignored.
-* `Exxxx` --- If the example is expected to fail to compile with a specific error code, include that code so that rustdoc will check that the expected code is used.
-
-When demonstrating success cases, many such cases may be included in a single code block. For failure cases, however, each example must appear in a separate code block so that the tests can ensure that each case indeed fails and fails with the appropriate error code or codes.
-
-See the [rustdoc documentation] for more detail.
-
-[rustdoc documentation]: https://doc.rust-lang.org/rustdoc/documentation-tests.html
-
-You can verify the samples pass by running `mdbook test`.
-
-### Linkcheck
-
-To verify that links are not broken, run `cargo xtask linkcheck`.
-
-### Running all tests
-
-As a last step before opening a PR, it is recommended to run `cargo xtask test-all`. This will go through and run most of the tests that are required for CI to pass. See `xtask/src/main.rs` for what all this does.
-
-## Special markdown constructs
-
-The following are extensions provided by [`mdbook-spec`](https://github.com/rust-lang/spec/tree/main/mdbook-spec).
-
-### Rules
-
-Most clauses should be preceded with a rule. Rules can be specified in the markdown source with the following on a line by itself:
-
-```markdown
-r[foo.bar]
-```
-
-The rule name should be lowercase, with periods separating from most general to most specific (like `r[array.repeat.zero]`).
-
-Rules can be linked to by their ID using markdown such as `[foo.bar]`. There are automatic link references so that any rule can be referred to from any page in the book.
-
-In the HTML, the rules are clickable just like headers.
-
-When assigning rules to new paragraphs, or when modifying rule names, use the following guidelines:
-
-1. A rule applies to one core idea, which should be easily determined when reading the paragraph it is applied to.
-2. Other than the "intro" paragraph, purely explanatory, expository, or exemplary content does not need a rule. If the expository paragraph isn't directly related to the previous, separate it with a hard (rendered) line break.
- * This content will be moved to `[!NOTE]` or more specific admonitions in the future.
-3. Rust code examples and tests do not need their own rules.
-4. Use the following guidelines for admonitions:
- * Notes: Do not include a rule.
- * Warning: Omit the rule if the warning follows from the previous paragraph or if the warning is explanatory and doesn't introduce any new rules.
- * Target specific behavior: Always include the rule.
- * Edition differences: Always include the rule.
-5. The following keywords should be used to identify paragraphs when unambiguous:
- * `intro`: The beginning paragraph of each section - should explain the construct being defined overall.
- * `syntax`: Syntax definitions or explanations when BNF syntax definitions are not used.
- * `namespace`: For items only, specifies the namespace(s) the item introduces a name in. May also be used elsewhere when defining a namespace (e.g. `r[attribute.diagnostic.namespace]`).
-6. When a rule doesn't fall under the above keywords, or for section rule ids, name the subrule as follows:
- * If the rule is naming a specific Rust language construct (e.g. an attribute, standard library type/function, or keyword-introduced concept), use the construct as named in the language, appropriately case-adjusted (but do not replace `_`s with `-`s).
- * Other than Rust language concepts with `_`s in the name, use `-` characters to separate words within a "subrule".
- * Whenever possible, do not repeat previous components of the rule.
- * Edition differences admonitions should typically be named by the edition where the behavior changed. You should be able to correspond the dates to the chapters in .
- * Target specific admonitions should typically be named by the least specific target property to which they apply (e.g. if a rule affects all x86 CPUs, the rule name should include `x86` rather than separately listing `i586`, `i686` and `x86_64`, and if a rule applies to all ELF platforms, it should be named `elf` rather than listing every ELF OS).
- * Use an appropriately descriptive, but short, name if the language does not provide one.
-
-#### Test rule annotations
-
-Tests in can be linked to rules in the reference. The rule will include a link to the tests, and there is also an [appendix] which tracks how the rules are currently linked.
-
-Tests in the `tests` directory can be annotated with the `//@ reference: x.y.z` header to link it to a rule. The header can be specified multiple times if a single file covers multiple rules.
-
-Compiler developers are not expected to add `reference` annotations to tests. However, if they do want to help, their cooperation is very welcome. Reference authors and editors are responsible for making sure every rule has a test associated with it.
-
-The tests are beneficial for reviewers to see the behavior of a rule. It is also a benefit to readers who may want to see examples of particular behaviors. When adding new rules, you should wait until the reference side is approved before submitting a PR to `rust-lang/rust` (to avoid churn if we decide on different names).
-
-Prefixed rule names should not be used in tests. That is, do not use something like `asm.rules` when there are specific rules like `asm.rules.reg-not-input`.
-
-We are not expecting 100% coverage at any time. Although it would be nice, it is unrealistic due to the sequence things are developed, and resources available.
-
-[appendix]: https://doc.rust-lang.org/nightly/reference/test-summary.html
-
-### Standard library links
-
-You should link to the standard library without specifying a URL in a fashion similar to [rustdoc intra-doc links][intra]. Some examples:
-
-We can link to the page on `Option`:
-
-```markdown
-[`std::option::Option`]
-```
-
-In these links, generics are ignored and can be included:
-
-```markdown
-[`std::option::Option`]
-```
-
-If we don't want the full path in the text, we can write:
-
-```markdown
-[`Option`](std::option::Option)
-```
-
-Macros can end in `!`. This can be helpful for disambiguation. For example, this refers to the macro rather than the module:
-
-```markdown
-[`alloc::vec!`]
-```
-
-Explicit namespace disambiguation is also supported:
-
-```markdown
-[`std::vec`](mod@std::vec)
-```
-
-Beware there are some limitations, for example:
-
-- Links to rexports from `std_arch` don't work due to .
-- Links to keywords aren't supported.
-- Links to trait impls where the trait is not in the prelude doesn't work. Traits must be in scope, and there currently isn't a way to add those.
-- If there are multiple generic implementations, it will link to one randomly (see ).
-
-When running into a rustdoc limitation, consider manually linking to the correct page using a relative link. For example, `../std/arch/macro.is_x86_feature_detected.html`.
-
-[intra]: https://doc.rust-lang.org/rustdoc/write-documentation/linking-to-items-by-name.html
-
-### Admonitions
-
-Admonitions use a style similar to GitHub-flavored markdown, where the style name is placed at the beginning of a blockquote, such as:
-
-```markdown
-> [!WARNING]
-> This is a warning.
-
-> [!NOTE]
-> This is a note.
-
-> [!EDITION-2024]
-> This is an edition-specific difference.
-
-> [!EXAMPLE]
-> This is an example.
-```
-
-The color and styling is defined in [`theme/reference.css`](https://github.com/rust-lang/reference/blob/master/theme/reference.css) and the transformation and icons are in [`mdbook-spec/src/admonitions.rs`](https://github.com/rust-lang/reference/blob/HEAD/mdbook-spec/src/admonitions.rs).
-
-## Style
-
-Idioms and styling:
-
-* Use American English spelling.
-* Use Oxford commas.
-* Avoid slashes for alternatives ("program/binary"); use conjunctions or rewrite it ("program or binary").
-* Avoid qualifying something as "in Rust"; the entire reference is about Rust.
-
## Content guidelines
The following are guidelines for the content of the reference.
@@ -222,11 +25,3 @@ r[foo.bar.edition2021]
> [!EDITION-2021]
> Describe what changed in 2021.
```
-
-## Grammar
-
-See [Grammar](grammar.md) for details on how to write grammar rules.
-
-## Attributes
-
-See the [attribute template](attribute-template.md) for how attributes should be formatted.
diff --git a/docs/grammar.md b/docs/grammar.md
deleted file mode 100644
index 190782bba4..0000000000
--- a/docs/grammar.md
+++ /dev/null
@@ -1,128 +0,0 @@
-# Grammar
-
-The Reference grammar is written in markdown code blocks using a modified BNF-like syntax (with a blend of regex and other arbitrary things). The `mdbook-spec` extension parses these rules and converts them to a renderable format, including railroad diagrams.
-
-The code block should have a lang string with the word "grammar", a comma, and the category of the grammar, like this:
-
-~~~
-```grammar,items
-ProductionName -> SomeExpression
-```
-~~~
-
-The category is used to group similar productions on the grammar summary page in the appendix.
-
-## Grammar syntax
-
-The syntax for the grammar itself is pretty close to what is described in the [Notation chapter](../src/notation.md), though there are some rendering differences.
-
-A "root" production, marked with `@root`, is one that is not used in any other production.
-
-The syntax for the grammar itself (written in itself, hopefully that's not too confusing) is:
-
-```
-Grammar -> Production+
-
-BACKTICK -> U+0060
-
-LF -> U+000A
-
-Production ->
- ( Comment LF )*
- `@root`? Name ` ->` Expression
-
-Name -> +
-
-Expression -> Sequence (` `* `|` ` `* Sequence)*
-
-Sequence -> (` `* AdornedExpr)+
-
-AdornedExpr -> ExprRepeat Suffix? Footnote?
-
-Suffix -> ` _` * `_`
-
-Footnote -> `[^` ~[`]` LF]+ `]`
-
-ExprRepeat ->
- Expr1 `?`
- | Expr1 `*?`
- | Expr1 `*`
- | Expr1 `+?`
- | Expr1 `+`
- | Expr1 `{` Range? `..` Range? `}`
-
-Range -> [0-9]+
-
-Expr1 ->
- Unicode
- | NonTerminal
- | Break
- | Comment
- | Terminal
- | Charset
- | Prose
- | Group
- | NegativeExpression
-
-Unicode -> `U+` [`A`-`Z` `0`-`9`]4..4
-
-NonTerminal -> Name
-
-Break -> LF ` `+
-
-Comment -> `//` ~[LF]+
-
-Terminal -> BACKTICK ~[LF]+ BACKTICK
-
-Charset -> `[` (` `* Characters)+ ` `* `]`
-
-Characters ->
- CharacterRange
- | CharacterTerminal
- | CharacterName
-
-CharacterRange -> BACKTICK BACKTICK `-` BACKTICK BACKTICK
-
-CharacterTerminal -> Terminal
-
-CharacterName -> Name
-
-Prose -> `<` ~[`>` LF]+ `>`
-
-Group -> `(` ` `* Expression ` `* `)`
-
-NegativeExpression -> `~` ( Charset | Terminal | NonTerminal )
-```
-
-The general format is a series of productions separated by blank lines. The expressions are:
-
-| Expression | Example | Description |
-|------------|---------|-------------|
-| Unicode | U+0060 | A single unicode character. |
-| NonTerminal | FunctionParameters | A reference to another production by name. |
-| Break | | This is used internally by the renderer to detect line breaks and indentation. |
-| Comment | // Single line comment. | A comment extending to the end of the line. |
-| Terminal | \`example\` | This is a sequence of exact characters, surrounded by backticks |
-| Charset | [ \`A\`-\`Z\` \`0\`-\`9\` \`_\` ] | A choice from a set of characters, space separated. There are three different forms. |
-| CharacterRange | [ \`A\`-\`Z\` ] | A range of characters, each character should be in backticks.
-| CharacterTerminal | [ \`x\` ] | A single character, surrounded by backticks. |
-| CharacterName | [ LF ] | A nonterminal, referring to another production. |
-| Prose | \ | This is an English description of what should be matched, surrounded in angle brackets. |
-| Group | (\`,\` Parameter)+ | This groups an expression for the purpose of precedence, such as applying a repetition operator to a sequence of other expressions.
-| NegativeExpression | ~[\` \` LF] | Matches anything except the given Charset, Terminal, or Nonterminal. |
-| Sequence | \`fn\` Name Parameters | A sequence of expressions, where they must match in order. |
-| Alternation | Expr1 \| Expr2 | Matches only one of the given expressions, separated by the vertical pipe character. |
-| Suffix | \_except \[LazyBooleanExpression\]\_ | This adds a suffix to the previous expression to provide an additional English description to it, rendered in subscript. This can have limited markdown, but try to avoid anything except basics like links. |
-| Footnote | \[^extern-safe\] | This adds a footnote, which can supply some extra information that may be helpful to the user. The footnote itself should be defined outside of the code block like a normal markdown footnote. |
-| Optional | Expr? | The preceding expression is optional. |
-| Repeat | Expr* | The preceding expression is repeated 0 or more times. |
-| Repeat (non-greedy) | Expr*? | The preceding expression is repeated 0 or more times without being greedy. |
-| RepeatPlus | Expr+ | The preceding expression is repeated 1 or more times. |
-| RepeatPlus (non-greedy) | Expr+? | The preceding expression is repeated 1 or more times without being greedy. |
-| RepeatRange | Expr{2..4} | The preceding expression is repeated between the range of times specified. Either bounds can be excluded, which works just like Rust ranges. |
-
-## Automatic linking
-
-The plugin automatically adds markdown link definitions for all the production names on every page. If you want to link directly to a production name, all you need to do is surround it in square brackets, like `[ArrayExpression]`.
-
-In some cases there might be name collisions with the automatic linking of rule names. In that case, disambiguate with the `grammar-` prefix, such as `[Type][grammar-Type]`. You can also do that if you just feel like being more explicit.
diff --git a/mdbook-spec/src/grammar.rs b/mdbook-spec/src/grammar.rs
index b0c2c58177..9c504ae25b 100644
--- a/mdbook-spec/src/grammar.rs
+++ b/mdbook-spec/src/grammar.rs
@@ -78,6 +78,8 @@ enum ExpressionKind {
Charset(Vec),
/// ``~[` ` LF]``
NegExpression(Box),
+ /// `A ^ B`
+ Cut(Box, Box),
/// `U+0060`
Unicode(String),
}
@@ -128,6 +130,10 @@ impl Expression {
| ExpressionKind::NegExpression(e) => {
e.visit_nt(callback);
}
+ ExpressionKind::Cut(e1, e2) => {
+ e1.visit_nt(callback);
+ e2.visit_nt(callback);
+ }
ExpressionKind::Alt(es) | ExpressionKind::Sequence(es) => {
for e in es {
e.visit_nt(callback);
diff --git a/mdbook-spec/src/grammar/parser.rs b/mdbook-spec/src/grammar/parser.rs
index 39bba771e3..6525a1ddfc 100644
--- a/mdbook-spec/src/grammar/parser.rs
+++ b/mdbook-spec/src/grammar/parser.rs
@@ -173,11 +173,12 @@ impl Parser<'_> {
match es.len() {
0 => Ok(None),
1 => Ok(Some(es.pop().unwrap())),
- _ => Ok(Some(Expression {
- kind: ExpressionKind::Alt(es),
- suffix: None,
- footnote: None,
- })),
+ _ => {
+ if let ExpressionKind::Cut(_, _) = es.last().unwrap().kind {
+ bail!(self, "expected final arm to not contain cut operator");
+ }
+ Ok(Some(Expression::new_kind(ExpressionKind::Alt(es))))
+ }
}
}
@@ -185,6 +186,9 @@ impl Parser<'_> {
let mut es = Vec::new();
loop {
self.space0();
+ if self.peek() == Some(b'^') {
+ return Ok(Some(self.parse_cut(es)?));
+ }
let Some(e) = self.parse_expr1()? else {
break;
};
@@ -201,6 +205,34 @@ impl Parser<'_> {
}
}
+ /// Parse cut (`^`) operator.
+ fn parse_cut(&mut self, mut es: Vec) -> Result {
+ self.expect("^", "expected `^`")?;
+ let Some(last_expr) = es.last() else {
+ bail!(self, "expected expression before cut operator");
+ };
+ match last_expr.kind {
+ ExpressionKind::Optional(_)
+ | ExpressionKind::Repeat(_)
+ | ExpressionKind::RepeatNonGreedy(_)
+ | ExpressionKind::RepeatRange(_, None | Some(0), _) => {
+ bail!(self, "expected non-optional expression before cut operator");
+ }
+ _ => {}
+ }
+ let Some(rhs) = self.parse_seq()? else {
+ bail!(self, "expected expression after cut operator");
+ };
+ let lhs = match es.len() {
+ 1 => es.pop().unwrap(),
+ _ => Expression::new_kind(ExpressionKind::Sequence(es)),
+ };
+ Ok(Expression::new_kind(ExpressionKind::Cut(
+ Box::new(lhs),
+ Box::new(rhs),
+ )))
+ }
+
fn parse_expr1(&mut self) -> Result