# dtolnay/syn

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/dtolnay-syn).**

3,292 stars · 360 forks · Rust · apache-2.0

## Links

- GitHub: https://github.com/dtolnay/syn
- awesome-repositories: https://awesome-repositories.com/repository/dtolnay-syn.md

## Topics

`proc-macro`

## Description

syn is a Rust syntax tree parser and token stream converter. It serves as a toolkit for procedural macro development, providing a framework to parse Rust source code into structured syntax trees for analysis and transformation.

The project enables the manipulation of Rust abstract syntax trees through specialized visitor and folder patterns for traversing and mutating nodes. It provides a bidirectional mapping that allows developers to convert token streams into structured trees and print those trees back into tokens for code generation.

The library covers a broad range of syntax analysis capabilities, including the parsing of expressions, type definitions, and top-level items. It also includes mechanisms for tracking source code spans to support precise error reporting and the ability to define custom syntax for specific identifiers or symbols.

## Tags

### Programming Languages & Runtimes

- [Toolkits](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/metaprogramming/procedural-macros/attribute-macro-code-generators/toolkits.md) — Provides a complete toolkit for parsing Rust source code into structured trees for procedural macro development.
- [Procedural Macros](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/language-features/metaprogramming/procedural-macros.md) — Offers a comprehensive set of tools for manipulating Rust tokens and syntax trees within the procedural macro system.
- [Token Stream Converters](https://awesome-repositories.com/f/programming-languages-runtimes/lexical-token-streams/token-stream-converters.md) — Provides a bidirectional mapping to convert between Rust token streams and structured syntax tree representations.
- [Source Code Abstract Syntax Trees](https://awesome-repositories.com/f/programming-languages-runtimes/programming-utilities/data-structure-type-helpers/data-structures/hierarchical-tree-structures/source-code-abstract-syntax-trees.md) — Provides a tree-based representation of source code that identifies the location and range of nodes. ([source](https://docs.rs/syn/2.0/syn/enum.Item.html))
- [Rust Code Generators](https://awesome-repositories.com/f/programming-languages-runtimes/rust-code-generators.md) — Turns structured data or modified syntax trees back into valid Rust tokens for automated source file creation.
- [Source File Parsing](https://awesome-repositories.com/f/programming-languages-runtimes/source-file-parsing.md) — Converts complete source files into structured syntax trees for analysis and transformation. ([source](https://docs.rs/syn/2.0/syn/struct.File.html))
- [Source Span Trackers](https://awesome-repositories.com/f/programming-languages-runtimes/source-span-trackers.md) — Retrieves the precise source code location and range for syntax nodes to enable accurate error reporting. ([source](https://docs.rs/syn/2.0/syn/struct.File.html))
- [Source Token Generation](https://awesome-repositories.com/f/programming-languages-runtimes/source-token-generation.md) — Prints syntax tree nodes back into tokens of source code for use in Rust macro expansion. ([source](https://docs.rs/syn))
- [Symmetric Token Printing](https://awesome-repositories.com/f/programming-languages-runtimes/symmetric-token-printing.md) — Provides a bidirectional mapping to convert structured syntax nodes back into compatible token streams.
- [Syntax-to-Token Printers](https://awesome-repositories.com/f/programming-languages-runtimes/syntax-to-token-printers.md) — Transforms represented syntax tree nodes back into token streams for use in code generation. ([source](https://docs.rs/syn/2.0/syn/enum.Item.html))
- [Token Stream Intermediation](https://awesome-repositories.com/f/programming-languages-runtimes/token-stream-intermediation.md) — Implements a translation layer between raw source text and structured syntax trees using token sequences.
- [Custom Syntax Handlers](https://awesome-repositories.com/f/programming-languages-runtimes/custom-syntax-handlers.md) — Allows the definition of custom types to parse specific identifiers or symbols as keywords. ([source](https://docs.rs/syn))
- [Grammatical Ambiguity Resolution](https://awesome-repositories.com/f/programming-languages-runtimes/grammatical-ambiguity-resolution.md) — Parses tokens using specific boundary rules to resolve grammatical ambiguities between structural elements. ([source](https://docs.rs/syn/2.0/syn/enum.Expr.html))
- [Lookahead Parsing](https://awesome-repositories.com/f/programming-languages-runtimes/lookahead-parsing.md) — Includes a mechanism to inspect future tokens to resolve grammatical ambiguities during tree construction.
- [Parsing Lookahead Analysis](https://awesome-repositories.com/f/programming-languages-runtimes/parsing-lookahead-analysis.md) — Determines if the next token in a stream can validly start an expression to guide parsing decisions. ([source](https://docs.rs/syn/2.0/syn/enum.Expr.html))
- [Source Code Analysis Tools](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-analysis-tools.md) — Converts Rust tokens into searchable tree representations to analyze code patterns and enforce architectural constraints.
- [Speculative Parsers](https://awesome-repositories.com/f/programming-languages-runtimes/speculative-parsers.md) — Provides a lookahead mechanism to decide the parsing path without consuming tokens from the stream. ([source](https://docs.rs/syn/2.0/syn/parse/index.html))

### Software Engineering & Architecture

- [Abstract Syntax Tree Parsing](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing.md) — Converts token streams into structured syntax trees for analysis and transformation. ([source](https://docs.rs/syn/2.0/syn/parse/index.html))
- [Rust Parsers](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing/rust-parsers.md) — Parses Rust source code into a structured syntax tree for analysis and transformation.
- [Type Definition Parsing](https://awesome-repositories.com/f/software-engineering-architecture/abstract-syntax-tree-parsing/type-definition-parsing.md) — Converts token streams into syntax trees representing paths, references, pointers, and trait objects. ([source](https://docs.rs/syn/2.0/syn/enum.Type.html))
- [AST Visitor Patterns](https://awesome-repositories.com/f/software-engineering-architecture/ast-visitor-patterns.md) — Provides a framework for traversing and mutating Rust abstract syntax trees using visitor and folder patterns.
- [Syntax Parsing Engines](https://awesome-repositories.com/f/software-engineering-architecture/syntax-parsing-engines.md) — Parses token streams into structured syntax trees representing top-level Rust declarations. ([source](https://docs.rs/syn/2.0/syn/enum.Item.html))
- [Syntax Traversal](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-traversal.md) — Provides visitor patterns to traverse syntax tree nodes for read-only analysis. ([source](https://docs.rs/syn))
- [Syntax Tree Mutation](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-traversal/syntax-tree-mutation.md) — Traverses syntax trees to modify nodes in place or transform them into new owned trees. ([source](https://docs.rs/syn))
- [Tree Mutations](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-traversal/tree-mutations.md) — Implements specialized visitor and folder patterns for traversing and mutating Rust abstract syntax trees.
- [Tree Mutators](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-traversal/tree-mutators.md) — Provides specialized folder patterns to analyze and mutate syntax tree nodes during traversal. ([source](https://cdn.jsdelivr.net/gh/dtolnay/syn@master/README.md))
- [Syntax Tree Printing](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-tree-printing.md) — Converts structured syntax tree nodes back into token streams for use in code generation. ([source](https://cdn.jsdelivr.net/gh/dtolnay/syn@master/README.md))
- [Syntax Tree Transformers](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-tree-transformers.md) — Implements folder patterns to transform an owned syntax tree into a modified version for code generation. ([source](https://docs.rs/syn))
- [Tree Mutations](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/tree-mutations.md) — Implements a folder-based transformation pattern to mutate Rust abstract syntax trees for code generation.
- [Compiler Diagnostic Toolkits](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/compiler-diagnostic-toolkits.md) — Tracks source code spans throughout the parsing and transformation process to deliver precise error messages.
- [Parse Error Reporters](https://awesome-repositories.com/f/software-engineering-architecture/error-handling/parse-error-reporters.md) — Generates detailed error messages identifying the specific tokens causing syntax failures. ([source](https://docs.rs/syn/2.0/syn/parse/index.html))
- [Error Reporting](https://awesome-repositories.com/f/software-engineering-architecture/error-reporting.md) — Reports precise errors by tracking span information across the macro expansion process. ([source](https://docs.rs/syn/2.0.118/syn/))
- [Compiler Error Emissions](https://awesome-repositories.com/f/software-engineering-architecture/error-reporting/custom-error-interfaces/compiler-error-emissions.md) — Tracks span information during expansion to trigger precise compiler error messages. ([source](https://docs.rs/syn/latest/syn/))

### Content Management & Publishing

- [Token Stream Serialization](https://awesome-repositories.com/f/content-management-publishing/content-processing-transformation/document-processing-conversion/document-processing/format-specific-parsers/markdown-abstract-syntax-trees/tree-to-text-serializers/token-stream-serialization.md) — Transforms structured syntax tree nodes back into token streams for use in code generation. ([source](https://docs.rs/syn/2.0/syn/struct.DeriveInput.html))

### Data & Databases

- [Recursive Descent Parsers](https://awesome-repositories.com/f/data-databases/data-transformation-functions/recursive-processors/recursive-logic-implementations/recursive-descent-parsers.md) — Uses a recursive descent parsing strategy to convert Rust token streams into structured syntax trees.
- [Visitor Pattern Traversers](https://awesome-repositories.com/f/data-databases/visitor-pattern-traversers.md) — Implements the visitor pattern to separate syntax tree traversal logic from node-specific operations.

### Development Tools & Productivity

- [Source Span Tracking](https://awesome-repositories.com/f/development-tools-productivity/ast-transformation-tools/ast-node-interpolation/node-metadata-attachments/source-span-tracking.md) — Provides a tree structure that attaches original source code offsets to every node for precise error reporting.
- [Source Code Error Location Reporters](https://awesome-repositories.com/f/development-tools-productivity/source-code-error-location-reporters.md) — Identifies the precise location and range of a syntax tree node within the original source code. ([source](https://docs.rs/syn/2.0/syn/struct.DeriveInput.html))

### Hardware & IoT

- [Syntax-to-Token Conversion](https://awesome-repositories.com/f/hardware-iot/integration-performance/hardware-interfacing-integration/hardware-interfacing/midi-and-osc-interfaces/midi-processing-engines/midi-to-token-converters/syntax-to-token-conversion.md) — Converts syntax tree nodes back into token streams to regenerate the original source code. ([source](https://docs.rs/syn/2.0/syn/struct.File.html))
