From f7d12101f89b7a1bbf34f12c9f43ad557627888e Mon Sep 17 00:00:00 2001 From: Vladimir Motylenko Date: Fri, 12 May 2023 21:17:43 +0300 Subject: [PATCH] release: First release of a fork --- .gitignore | 3 +- CHANGELOG.md | 21 +++++++--- CHANGELOG.old => CHANGELOG.old.md | 14 +++++++ Cargo.toml | 10 ++--- README.md | 50 +++++++++++++++++++----- benches/bench.rs | 12 +++--- cliff.toml | 2 +- examples/html-to-string-macro/Cargo.toml | 6 +-- examples/html-to-string-macro/README.md | 2 +- examples/html-to-string-macro/src/lib.rs | 4 +- generate_changelog.sh | 4 +- src/config.rs | 2 +- src/lib.rs | 16 ++++---- src/node/tokens.rs | 2 +- tests/recoverable_parser.rs | 2 +- tests/test.rs | 2 +- 16 files changed, 104 insertions(+), 48 deletions(-) rename CHANGELOG.old => CHANGELOG.old.md (92%) diff --git a/.gitignore b/.gitignore index 2ebc5ea..1d14bc1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/Cargo.lock \ No newline at end of file +/Cargo.lock +.DS_Store \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index fe493f2..3a20ae1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,18 +12,14 @@ All notable changes to this project will be documented in this file. - Make Node types clonable. - Fix recoverable parser. Now try to recover if any sequence is incorrect. - Bump syn_derive to 0.1.6 to avoid nightly +- Start a new version history ### Documentation -- Mixed name punctuation and node span ([#44](https://github.com/stoically/syn-rsx/issues/44)) -- Missing module documentation ([#45](https://github.com/stoically/syn-rsx/issues/45)) -- Fix formatting ([#46](https://github.com/stoically/syn-rsx/issues/46)) -- Fix code block ([#47](https://github.com/stoically/syn-rsx/issues/47)) - Add comparsion with syn-rsx ### Features -- Track the source span for all nodes ([#42](https://github.com/stoically/syn-rsx/issues/42)) - Remove attributes from node list, and make type guaranties that attribute will be stored only in Element - Improve tag close handling. - Allow parsing of invalid rust code blocks @@ -37,6 +33,7 @@ All notable changes to this project will be documented in this file. - Attribute value parsing span - Updated example, bench, made fragment parsing recoverable. - Make public keyed attribute fields. +- RawText to_source implementation on stable ### Refactor @@ -57,6 +54,20 @@ Use RecoverableContext instead. - TRYBUILD=overwrite in ui tests + +## [unreleased] + +### Documentation + +- Mixed name punctuation and node span ([#44](https://github.com/stoically/syn-rsx/issues/44)) +- Missing module documentation ([#45](https://github.com/stoically/syn-rsx/issues/45)) +- Fix formatting ([#46](https://github.com/stoically/syn-rsx/issues/46)) +- Fix code block ([#47](https://github.com/stoically/syn-rsx/issues/47)) + +### Features + +- Track the source span for all nodes ([#42](https://github.com/stoically/syn-rsx/issues/42)) + ## [0.9.0] - 2022-11-10 ### Documentation diff --git a/CHANGELOG.old b/CHANGELOG.old.md similarity index 92% rename from CHANGELOG.old rename to CHANGELOG.old.md index 029b15b..83257b2 100644 --- a/CHANGELOG.old +++ b/CHANGELOG.old.md @@ -1,3 +1,17 @@ + +## [unreleased] + +### Documentation + +- Mixed name punctuation and node span ([#44](https://github.com/stoically/syn-rsx/issues/44)) +- Missing module documentation ([#45](https://github.com/stoically/syn-rsx/issues/45)) +- Fix formatting ([#46](https://github.com/stoically/syn-rsx/issues/46)) +- Fix code block ([#47](https://github.com/stoically/syn-rsx/issues/47)) + +### Features + +- Track the source span for all nodes ([#42](https://github.com/stoically/syn-rsx/issues/42)) + ## [0.9.0] - 2022-11-10 ### Documentation diff --git a/Cargo.toml b/Cargo.toml index 10d83c1..f838798 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,11 @@ [package] -name = "syn-rsx" -description = "syn-powered parser for JSX-like TokenStreams" -version = "0.9.0" -authors = ["stoically "] +name = "rstml" +description = "Rust templating parser for JSX-like TokenStreams" +version = "0.10.0" +authors = ["vldm ","stoically "] keywords = ["syn", "jsx", "rsx", "html", "macro"] edition = "2018" -repository = "https://github.com/stoically/syn-rsx" +repository = "https://github.com/rs-tml/rstml" readme = "README.md" license = "MIT" resolver = "2" diff --git a/README.md b/README.md index 3611b01..a78e799 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -# syn-rsx +# rstml -[![crates.io page](https://img.shields.io/crates/v/syn-rsx.svg)](https://crates.io/crates/syn-rsx) -[![docs.rs page](https://docs.rs/syn-rsx/badge.svg)](https://docs.rs/syn-rsx/) -[![codecov](https://codecov.io/gh/stoically/syn-rsx/branch/main/graph/badge.svg?token=2LMJ8YEV92)](https://codecov.io/gh/stoically/syn-rsx) -![build](https://github.com/stoically/syn-rsx/workflows/ci/badge.svg) -![license: MIT](https://img.shields.io/crates/l/syn-rsx.svg) +[![crates.io page](https://img.shields.io/crates/v/rstml.svg)](https://crates.io/crates/rstml) +[![docs.rs page](https://docs.rs/rstml/badge.svg)](https://docs.rs/rstml/) +[![codecov](https://codecov.io/gh/rs-tml/rstml/branch/main/graph/badge.svg?token=2LMJ8YEV92)](https://codecov.io/gh/rs-tml/rs-tml) +![build](https://github.com/rs-tml/rstml/workflows/ci/badge.svg) +![license: MIT](https://img.shields.io/crates/l/rstml.svg) -[`syn`]-powered parser for JSX-like [`TokenStream`]s, 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. +Rust templating parser for JSX-like [`TokenStream`]s, 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. The fork of original [syn-rsx](https://github.com/stoically/syn-rsx) repo. It was created because of various reasons: @@ -14,6 +14,7 @@ It was created because of various reasons: - Syn v2 was released and `syn-rsx` need to be mooved to new version. - The idea of [lossless parsing](https://github.com/stoically/syn-rsx/issues/53) was left unattended. - [Unquoted text](https://github.com/stoically/syn-rsx/issues/2) feature should advance. +- Interest in recoverable parsing and better IDE support. See [comparsion](/comparsion-with-syn-rsx.md) for more detail. @@ -23,7 +24,7 @@ use std::convert::TryFrom; use eyre::bail; use quote::quote; -use syn_rsx::{parse2, Node, NodeAttribute, NodeElement, NodeText}; +use rstml::{parse2, Node, NodeAttribute, NodeElement, NodeText}; // Create HTML `TokenStream`. let tokens = quote! { "hi" }; @@ -56,12 +57,22 @@ You might want to check out the [html-to-string-macro example] as well. - **Text nodes** - Support for [unquoted text is planned]. ```html
"String literal"
``` +- **Unquoted text nodes** + + Unquoted text is supported with few limitations: + - Only valid Rust TokenStream can be unquoted text (no single quote text is supported, no unclosed braces, etc.) + - Unquoted text not always can save spaces. It uses [`Span::source_text`] and [`Span::join`] to retrive info about spaces, and it is not always available. + - Quoted text near unquoted treated as diferent Node, end library user should decide whenever to preserve quotation. + + ```html +
Some string that is valid rust token stream
+ ``` + - **Node names separated by dash, colon or double colon** ```html @@ -123,6 +134,24 @@ You might want to check out the [html-to-string-macro example] as well. ``` +- **Recoverable parser** + + Can parse html with multiple mistakes. + As result library user get array of errors that can be reported, and tree of nodes that was parsed. + + ```html +
+ <> +
"1" +
"2"
+
"3"
+
+ + ``` + + Using this feature one can write macro in IDE friendly way. + This macro will work faster (because on invalid syntax it change output slightly, instead of removing it completely, so IDE can check diff quicly). And give completion (goto definition, and other semantic related feature) more often. + - **Customization** A `ParserConfig` to customize parsing behavior is available, so if you have @@ -135,7 +164,8 @@ You might want to check out the [html-to-string-macro example] as well. possible to have custom syntax in blocks. More details in [#9] [`syn`]: https://github.com/dtolnay/syn +[`Span::join`]: https://doc.rust-lang.org/proc_macro/struct.Span.html#method.join +[`Span::source_text`]: https://doc.rust-lang.org/proc_macro/struct.Span.html#method.source_text [`tokenstream`]: https://doc.rust-lang.org/proc_macro/struct.TokenStream.html [html-to-string-macro example]: https://github.com/stoically/syn-rsx/tree/main/examples/html-to-string-macro -[unquoted text is planned]: https://github.com/stoically/syn-rsx/issues/2 [#9]: https://github.com/stoically/syn-rsx/issues/9 diff --git a/benches/bench.rs b/benches/bench.rs index d3d94f6..5226559 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -20,9 +20,9 @@ fn criterion_benchmark(c: &mut Criterion) { }; - c.bench_function("syn_rsx::parse2", |b| { + c.bench_function("rstml::parse2(simple)", |b| { b.iter(|| { - let config = syn_rsx::ParserConfig::new().always_self_closed_elements( + let config = rstml::ParserConfig::new().always_self_closed_elements( vec![ "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr", @@ -30,12 +30,12 @@ fn criterion_benchmark(c: &mut Criterion) { .into_iter() .collect(), ); - syn_rsx::parse2_with_config(tokens.clone(), config) + rstml::parse2_with_config(tokens.clone(), config) }) }); - c.bench_function("syn_rsx::parse2(rust_site)", |b| { + c.bench_function("rstml::parse2(rust_site)", |b| { b.iter(|| { - let config = syn_rsx::ParserConfig::new().always_self_closed_elements( + let config = rstml::ParserConfig::new().always_self_closed_elements( vec![ "area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "param", "source", "track", "wbr", @@ -43,7 +43,7 @@ fn criterion_benchmark(c: &mut Criterion) { .into_iter() .collect(), ); - syn_rsx::parse2_with_config(RUST_SITE_SIMPLE.with(|tokens| tokens.clone()), config) + rstml::parse2_with_config(RUST_SITE_SIMPLE.with(|tokens|tokens.clone()), config) }) }); } diff --git a/cliff.toml b/cliff.toml index cd7832f..4ef37c1 100644 --- a/cliff.toml +++ b/cliff.toml @@ -35,7 +35,7 @@ filter_unconventional = false split_commits = false # regex for preprocessing the commit messages commit_preprocessors = [ - { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/stoically/syn-rsx/issues/${2}))"}, + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](https://github.com/rs-tml/rstml/issues/${2}))"}, ] # regex for parsing and grouping commits commit_parsers = [ diff --git a/examples/html-to-string-macro/Cargo.toml b/examples/html-to-string-macro/Cargo.toml index 03b5d83..11b966e 100644 --- a/examples/html-to-string-macro/Cargo.toml +++ b/examples/html-to-string-macro/Cargo.toml @@ -1,11 +1,11 @@ [package] name = "html-to-string-macro" -description = "simple html to string macro powered by syn-rsx" +description = "simple html to string macro powered by rstml" version = "0.2.5" authors = ["stoically "] keywords = ["html-to-string", "html", "macro"] edition = "2021" -repository = "https://github.com/stoically/syn-rsx/tree/main/examples/html-to-string-macro" +repository = "https://github.com/rs-tml/rstml/tree/main/examples/html-to-string-macro" readme = "README.md" license = "MIT" @@ -16,7 +16,7 @@ proc-macro = true proc-macro2 = "1.0.47" quote = "1.0.21" syn = "2.0.15" -syn-rsx = { path = "../../" } +rstml = { path = "../../" } [dev-dependencies] trybuild = "1.0" diff --git a/examples/html-to-string-macro/README.md b/examples/html-to-string-macro/README.md index e711325..3915f2a 100644 --- a/examples/html-to-string-macro/README.md +++ b/examples/html-to-string-macro/README.md @@ -5,4 +5,4 @@ ![build](https://github.com/stoically/syn-rsx/workflows/ci/badge.svg) ![license: MIT](https://img.shields.io/crates/l/html-to-string-macro.svg) -simple html to string macro powered by [syn-rsx](https://crates.io/crates/syn-rsx). +simple html to string macro powered by [rstml](https://crates.io/crates/rstml). diff --git a/examples/html-to-string-macro/src/lib.rs b/examples/html-to-string-macro/src/lib.rs index cba6ad2..015d274 100644 --- a/examples/html-to-string-macro/src/lib.rs +++ b/examples/html-to-string-macro/src/lib.rs @@ -4,7 +4,7 @@ use proc_macro::TokenStream; use proc_macro2::{Literal, TokenTree}; use quote::{quote, quote_spanned, ToTokens}; use syn::spanned::Spanned; -use syn_rsx::{Node, NodeAttribute, NodeName, Parser, ParserConfig}; +use rstml::{Node, NodeAttribute, NodeName, Parser, ParserConfig}; #[derive(Default)] struct WalkNodesOutput<'a> { @@ -115,7 +115,7 @@ fn walk_nodes<'a>(nodes: &'a Vec) -> WalkNodesOutput<'a> { /// Values returned from braced blocks `{}` are expected to return something /// that implements `Display`. /// -/// See [syn-rsx docs](https://docs.rs/syn-rsx/) for supported tags and syntax. +/// See [rstml docs](https://docs.rs/rstml/) for supported tags and syntax. /// /// # Example /// diff --git a/generate_changelog.sh b/generate_changelog.sh index 038a07e..7fa3fa6 100755 --- a/generate_changelog.sh +++ b/generate_changelog.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -GIT_CLIFF__CHANGELOG__FOOTER=$(cat CHANGELOG.old) -OLD_COMMIT="734000aed91c62392e0fa6f445b1fad734ba2a17" +GIT_CLIFF__CHANGELOG__FOOTER=$(cat CHANGELOG.old.md) +OLD_COMMIT="149109f1420df7a11f5a69e4a9fb90bf57ec4f02" git cliff -o CHANGELOG.md -- $OLD_COMMIT..HEAD \ No newline at end of file diff --git a/src/config.rs b/src/config.rs index d9bc0cf..2f4a7d4 100644 --- a/src/config.rs +++ b/src/config.rs @@ -121,7 +121,7 @@ impl ParserConfig { /// ```rust /// use quote::quote; /// use syn::Token; - /// use syn_rsx::{parse2_with_config, ParserConfig}; + /// use rstml::{parse2_with_config, ParserConfig}; /// /// let tokens = quote! { ///
{%}
diff --git a/src/lib.rs b/src/lib.rs index 27589d8..18a823a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,7 @@ //! //! use eyre::bail; //! use quote::quote; -//! use syn_rsx::{parse2, Node, NodeAttribute, NodeElement, NodeText}; +//! use rstml::{parse2, Node, NodeAttribute, NodeElement, NodeText}; //! //! // Create HTML `TokenStream`. //! let tokens = quote! { "hi" }; @@ -39,7 +39,7 @@ //! //! ```rust //! # use quote::quote; -//! # use syn_rsx::parse2; +//! # use rstml::parse2; //! # parse2(quote! { //! //! # }).unwrap(); @@ -51,7 +51,7 @@ //! //! ```rust //! # use quote::quote; -//! # use syn_rsx::parse2; +//! # use rstml::parse2; //! # parse2(quote! { //!
"String literal"
//! # }).unwrap(); @@ -61,7 +61,7 @@ //! //! ```rust //! # use quote::quote; -//! # use syn_rsx::parse2; +//! # use rstml::parse2; //! # parse2(quote! { //! //! @@ -72,7 +72,7 @@ //! //! ```rust //! # use quote::quote; -//! # use syn_rsx::parse2; +//! # use rstml::parse2; //! # parse2(quote! { //! //! # }).unwrap(); @@ -82,7 +82,7 @@ //! //! ```rust //! # use quote::quote; -//! # use syn_rsx::parse2; +//! # use rstml::parse2; //! # parse2(quote! { //! //! @@ -94,7 +94,7 @@ //! //! ```rust //! # use quote::quote; -//! # use syn_rsx::parse2; +//! # use rstml::parse2; //! # parse2(quote! { //! <{ let block = "in node name position"; } /> //!
{ let block = "in node position"; }
@@ -108,7 +108,7 @@ //! //! ```rust //! # use quote::quote; -//! # use syn_rsx::parse2; +//! # use rstml::parse2; //! # parse2(quote! { //!
//! # }).unwrap(); diff --git a/src/node/tokens.rs b/src/node/tokens.rs index f9cdbba..964ffef 100644 --- a/src/node/tokens.rs +++ b/src/node/tokens.rs @@ -262,7 +262,7 @@ impl RecoverableContext { /// Example: /// ```no_build /// # use syn::{parse::{Parser, ParseStream}, Ident, Result, parse_macro_input, Token}; - /// # use syn_rsx::{parse_tokens_until}; + /// # use rstml::{parse_tokens_until}; /// # fn main() -> syn::Result<()>{ /// let tokens:proc_macro2::TokenStream = quote::quote!(few idents seperated by spaces and then minus sign - that will stop parsing).into(); /// let concat_idents_without_minus = |input: ParseStream| -> Result { diff --git a/tests/recoverable_parser.rs b/tests/recoverable_parser.rs index e1fef1c..355ed50 100644 --- a/tests/recoverable_parser.rs +++ b/tests/recoverable_parser.rs @@ -4,7 +4,7 @@ use eyre::Result; use proc_macro2::TokenStream; use quote::quote; use syn::Block; -use syn_rsx::{Node, NodeAttribute, NodeBlock, Parser, ParserConfig}; +use rstml::{Node, NodeAttribute, NodeBlock, Parser, ParserConfig}; #[test] fn test_recover_incorrect_closing_tags() { diff --git a/tests/test.rs b/tests/test.rs index 3afeca6..96f382f 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -4,7 +4,7 @@ use eyre::Result; use proc_macro2::TokenStream; use quote::quote; use syn::Block; -use syn_rsx::{ +use rstml::{ parse2, parse2_with_config, KeyedAttribute, Node, NodeAttribute, NodeElement, NodeType, ParserConfig, };