7 unstable releases

0.4.2 Apr 14, 2024
0.4.1 Jul 21, 2023
0.4.0 Jun 24, 2023
0.3.1 Apr 3, 2023
0.1.0 May 8, 2019

#2136 in Procedural macros

Download history 7/week @ 2024-07-15 37/week @ 2024-07-22 15/week @ 2024-07-29 14/week @ 2024-08-05 8/week @ 2024-08-12 13/week @ 2024-08-19 28/week @ 2024-08-26 10/week @ 2024-09-02 7/week @ 2024-09-09 14/week @ 2024-09-16 34/week @ 2024-09-23 23/week @ 2024-09-30 15/week @ 2024-10-07 9/week @ 2024-10-14 18/week @ 2024-10-21 9/week @ 2024-10-28

53 downloads per month

MIT/Apache

10KB
99 lines

Data structures that describe Syn's syntax tree.

The Syn syntax tree is made up of more than 200 types. Occasionally it can come up that you need to implement some behavior across them all.

  • For example the Rust integration for AST Explorer wants to turn a syntax tree from Syn into a JavaScript value understood by the platform's existing cross-language syntax tree visualization code.

  • As another example from within Syn itself, the traits and implementations of the visit, visit_mut, and fold modules can be generated programmatically from a description of the syntax tree.

To make this type of code as easy as possible to implement in any language, every Syn release comes with a machine-readable description of that version of the syntax tree as a JSON file syn.json. This syn-codegen crate provides the canonical data structures for parsing and making use of the representation in syn.json from Rust code.

Example

use syn_codegen::Definitions;

const SYN: &str = include_str!("syn.json");

fn main() {
    let defs: Definitions = serde_json::from_str(SYN).unwrap();

    for node in &defs.types {
        println!("syn::{}", node.ident);
    }
}

Dependencies

~0.9–1.3MB
~23K SLoC