syn-rsx
syn-powered parser for JSX-like TokenStreams, aka RSX. 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.
use quote;
use parse2;
let tokens = quote! ;
let nodes = parse2.unwrap;
assert_eq!;
assert_eq!;
assert_eq!;
Features
-
Not opinionated
Every tag or attribute name is valid
-
Text nodes
"String literal"
Support for unquoted text is planned
-
Node names separated by dash, colon or double colon
-
Node names with reserved keywords
-
Attribute values can be any valid syn expression without requiring braces
-
Doctypes, Comments and Fragments
<!-- "comment" --> <></>
-
Braced blocks are parsed as arbitrary Rust code
<{ let block = "in node name position"; } /> { let block = "in node position"; }
-
Helpful error reporting out of the box
error: open tag has no corresponding close tag and is not self-closing -/html-to-string-macro/tests/lib.rs:5:24 | 5 | html_to_string! ;
-
Customization
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.One highlight with regards to customization is the
transform_block
configuration, which takes a closure that receives raw block content asParseStream
and lets you optionally convert it to aTokenStream
. That makes it possible to have custom syntax in blocks. More details in #9