• Home
  • Raw
  • Download

Lines Matching +full:rust +full:- +full:src

1 Parser for Rust source code
4 [<img alt="github" src="https://img.shields.io/badge/github-dtolnay/syn-8da0cb?style=for-the-badge&…
5 [<img alt="crates.io" src="https://img.shields.io/crates/v/syn.svg?style=for-the-badge&color=fc8d62…
6 [<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-syn-66c2a5?style=for-the-badge&labelC…
7 [<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/syn/CI/master?s…
9 Syn is a parsing library for parsing a stream of Rust tokens into a syntax tree
10 of Rust source code.
12 Currently this library is geared toward use in Rust procedural macros, but
15 - **Data structures** — Syn provides a complete syntax tree that can represent
16 any valid Rust source code. The syntax tree is rooted at [`syn::File`] which
21 - **Derives** — Of particular interest to derive macros is [`syn::DeriveInput`]
24 user-defined trait.
26 - **Parsing** — Parsing in Syn is built around [parser functions] with the
27 signature `fn(ParseStream) -> Result<T>`. Every syntax tree node defined by
32 - **Location information** — Every token parsed by Syn is associated with a
38 - **Feature flags** — Functionality is aggressively feature gated so your
62 [workshop]: https://github.com/dtolnay/proc-macro-workshop
68 The canonical derive macro using Syn looks like this. We write an ordinary Rust
70 we are deriving. Any time that derive appears in the user's code, the Rust
72 arbitrary Rust code to figure out what to do with those tokens, then hand some
75 [`TokenStream`]: https://doc.rust-lang.org/proc_macro/struct.TokenStream.html
83 proc-macro = true
86 ```rust
92 pub fn my_macro(input: TokenStream) -> TokenStream {
96 // Build the output, possibly using quasi-quotation
107 derive macro. It works on any Rust compiler 1.31+. The example derives a
113 ```rust
116 fn heap_size_of_children(&self) -> usize;
123 ```rust
137 The token-based procedural macro API provides great control over where the
141 ```rust
150 macro as shown in the `heapsize` example, token-based macros in Syn are able to
155 --> src/main.rs:7:5
165 The [`lazy-static`] example directory shows the implementation of a
169 [`lazy-static`]: examples/lazy-static
176 static ref USERNAME: Regex = Regex::new("^[a-z0-9_-]{3,16}$").unwrap();
185 --> src/main.rs:10:16
199 the Rust compiler in the expanded code following misuse of the macro. Such tests
210 generated code looks like. Use `cargo rustc -- -Zunstable-options
211 --pretty=expanded` or the [`cargo expand`] subcommand.
213 [`cargo expand`]: https://github.com/dtolnay/cargo-expand
217 test cases, run `cargo expand --test the_test_case` where the last argument is
220 This write-up by Brandon W Maister discusses debugging in more detail:
221 [Debugging Rust's new Custom Derive system][debugging].
223 [debugging]: https://quodlibetor.github.io/posts/debugging-rusts-new-custom-derive-system/
233 - **`derive`** *(enabled by default)* — Data structures for representing the
235 - **`full`** — Data structures for representing the syntax tree of all valid
236 Rust source code, including items and expressions.
237 - **`parsing`** *(enabled by default)* — Ability to parse input tokens into a
239 - **`printing`** *(enabled by default)* — Ability to print a syntax tree node as
240 tokens of Rust source code.
241 - **`visit`** — Trait for traversing a syntax tree.
242 - **`visit-mut`** — Trait for traversing and mutating in place a syntax tree.
243 - **`fold`** — Trait for transforming an owned syntax tree.
244 - **`clone-impls`** *(enabled by default)* — Clone impls for all syntax tree
246 - **`extra-traits`** — Debug, Eq, PartialEq, Hash impls for all syntax tree
248 - **`proc-macro`** *(enabled by default)* — Runtime dependency on the dynamic
255 Syn operates on the token representation provided by the [proc-macro2] crate
256 from crates.io rather than using the compiler's built in proc-macro crate
259 incompatible ecosystems for proc macros vs non-macro use cases.
261 In general all of your code should be written against proc-macro2 rather than
262 proc-macro. The one exception is in the signatures of procedural macro entry
265 The proc-macro2 crate will automatically detect and use the compiler's data
268 [proc-macro2]: https://docs.rs/proc-macro2/1.0/proc_macro2/
275 Licensed under either of <a href="LICENSE-APACHE">Apache License, Version
276 2.0</a> or <a href="LICENSE-MIT">MIT license</a> at your option.
283 for inclusion in this crate by you, as defined in the Apache-2.0 license, shall