[][src]Crate syn_rsx

syn-powered parser for JSX-like TokenStreams. The parsed result is a nested Node structure, similar to the browser DOM, where node name and value are syn expressions to support building proc macros. A ParserConfig to customize parsing behavior is available, so if you have slightly different requirements for parsing and it's not yet customizable feel free to open an issue or pull request to extend the configuration.

use quote::quote;
use syn_rsx::parse2;

let tokens = quote! {
    <div foo={bar}>
        <div>"hello"</div>
        <world />
    </div>
};

let nodes = parse2(tokens, None).unwrap();

let node = &nodes[0];
assert_eq!(node.attributes[0].name_as_string().unwrap(), "foo");

let children = &node.children;
assert_eq!(children.len(), 2);
assert_eq!(children[0].children[0].value_as_string().unwrap(), "hello");
assert_eq!(children[1].name_as_string().unwrap(), "world");

Modules

punctuation

Custom syn punctuations

Structs

Node

Node in the tree

Parser

RSX Parser

ParserConfig

Configures the Parser behavior

Enums

NodeName

Name of the node

NodeType

Type of the node

Functions

parse

Parse the given proc-macro::TokenStream into a Node tree

parse2

Parse the given proc-macro2::TokenStream into a Node tree