Skip to content

Commit

Permalink
release: First release of a fork
Browse files Browse the repository at this point in the history
  • Loading branch information
vldm committed May 13, 2023
1 parent ded41ca commit f7d1210
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/target
/Cargo.lock
/Cargo.lock
.DS_Store
21 changes: 16 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand Down
14 changes: 14 additions & 0 deletions CHANGELOG.old → CHANGELOG.old.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 5 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "syn-rsx"
description = "syn-powered parser for JSX-like TokenStreams"
version = "0.9.0"
authors = ["stoically <[email protected]>"]
name = "rstml"
description = "Rust templating parser for JSX-like TokenStreams"
version = "0.10.0"
authors = ["vldm <[email protected]>","stoically <[email protected]>"]
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"
Expand Down
50 changes: 40 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
# 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:
- The author of original `syn-rsx` retired, end left new features without attention https://github.com/stoically/syn-rsx/issues/49
- 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.
Expand All @@ -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! { <hello world>"hi"</hello> };
Expand Down Expand Up @@ -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
<div>"String literal"</div>
```

- **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
<div> Some string that is valid rust token stream </div>
```

- **Node names separated by dash, colon or double colon**

```html
Expand Down Expand Up @@ -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
<div hello={world.} /> <!-- dot after world is invalid syn expression -->
<>
<div>"1"</x> <!-- incorrect closed tag -->
<div>"2"</div>
<div>"3"</div>
<div {"some-attribute-from-rust-block"}/>
</>
```

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
Expand All @@ -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
12 changes: 6 additions & 6 deletions benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,30 @@ 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",
]
.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",
]
.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)
})
});
}
Expand Down
2 changes: 1 addition & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
6 changes: 3 additions & 3 deletions examples/html-to-string-macro/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>"]
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"

Expand All @@ -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"
2 changes: 1 addition & 1 deletion examples/html-to-string-macro/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
4 changes: 2 additions & 2 deletions examples/html-to-string-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -115,7 +115,7 @@ fn walk_nodes<'a>(nodes: &'a Vec<Node>) -> 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
///
Expand Down
4 changes: 2 additions & 2 deletions generate_changelog.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
/// <div>{%}</div>
Expand Down
16 changes: 8 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! { <hello world>"hi"</hello> };
Expand Down Expand Up @@ -39,7 +39,7 @@
//!
//! ```rust
//! # use quote::quote;
//! # use syn_rsx::parse2;
//! # use rstml::parse2;
//! # parse2(quote! {
//! <hello world />
//! # }).unwrap();
Expand All @@ -51,7 +51,7 @@
//!
//! ```rust
//! # use quote::quote;
//! # use syn_rsx::parse2;
//! # use rstml::parse2;
//! # parse2(quote! {
//! <div>"String literal"</div>
//! # }).unwrap();
Expand All @@ -61,7 +61,7 @@
//!
//! ```rust
//! # use quote::quote;
//! # use syn_rsx::parse2;
//! # use rstml::parse2;
//! # parse2(quote! {
//! <tag-name some:attribute-key="value" />
//! <tag::name attribute::key="value" />
Expand All @@ -72,7 +72,7 @@
//!
//! ```rust
//! # use quote::quote;
//! # use syn_rsx::parse2;
//! # use rstml::parse2;
//! # parse2(quote! {
//! <input type="submit" />
//! # }).unwrap();
Expand All @@ -82,7 +82,7 @@
//!
//! ```rust
//! # use quote::quote;
//! # use syn_rsx::parse2;
//! # use rstml::parse2;
//! # parse2(quote! {
//! <!DOCTYPE html>
//! <!-- "comment" -->
Expand All @@ -94,7 +94,7 @@
//!
//! ```rust
//! # use quote::quote;
//! # use syn_rsx::parse2;
//! # use rstml::parse2;
//! # parse2(quote! {
//! <{ let block = "in node name position"; } />
//! <div>{ let block = "in node position"; }</div>
Expand All @@ -108,7 +108,7 @@
//!
//! ```rust
//! # use quote::quote;
//! # use syn_rsx::parse2;
//! # use rstml::parse2;
//! # parse2(quote! {
//! <div key=some::value() />
//! # }).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/node/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
Expand Down
2 changes: 1 addition & 1 deletion tests/recoverable_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down

0 comments on commit f7d1210

Please sign in to comment.