News for hackers. Stuff that matters.
Re:Single Page Applications using Rust by devxpy on Tuesday August 11, 2020 @12:57PM (#24122583)
Can anyone please tell me how the author able to use html syntax in rust?

I get that there are macros, but how are html tags valid syntax? Is rust just interpreting the html content as strings?

I've only ever seen C macros, and I don't remember seeing this kind of wizardry happening there.

Re:Single Page Applications using Rust by Ciantic on Tuesday August 11, 2020 @01:07PM (#24122721)
It's using this: https://yew.rs/docs/concepts/html and no, just like JSX, it's not HTML strings. It's building HTML-like AST in macro.

One great thing about JSX (and Yew) is that it's way more secure way to build an HTML, because you don't need to worry about escaping behaviors as much. (Sometimes you still need, like injecting inline CSS etc. but not that often)

Re:Single Page Applications using Rust by devxpy on Tuesday August 11, 2020 @01:10PM (#24122759)
whoa, so you can write like a DSL parser using the rust macro matcher syntax?
Re:Single Page Applications using Rust by dgb23 on Tuesday August 11, 2020 @01:23PM (#24122926)
Essentially yes. Macros in Rust are very powerful, similar to Lisp macros (although they are naturally clunkier).

As you would expect, you will find macros for HTML, JSON etc. in libraries, but there are also quite a bunch of smaller, frequent macros that simply reduce common boilerplate.

Re:Single Page Applications using Rust by db48x on Tuesday August 11, 2020 @04:05PM (#24125347)
And then there are the Rust macros that let you write code in Lisp syntax, although I don't recall that any of them had a defmacro form…
Re:Single Page Applications using Rust by devxpy on Tuesday August 11, 2020 @11:14PM (#24128279)
Oh god, what have I seen
Re:Single Page Applications using Rust by db48x on Wednesday August 12, 2020 @11:20AM (#24132927)
I'm sorry; I should have thought about the more sensitive readers.
Re:Single Page Applications using Rust by nulptr on Tuesday August 11, 2020 @01:27PM (#24123002)
rust allows for procedural macros (basically a function that takes a token stream and returns a token stream, and yes you can do parsing in this funciton

https://doc.rust-lang.org/reference/procedural-macros.html

Re:Single Page Applications using Rust by kevincox on Tuesday August 11, 2020 @06:36PM (#24126804)
Macros in Rust don't need to be completely valid syntax. There are some requirements such as balanced parens and strings but the macro API is basically a token stream. The syntax requirements are just so that the compiler knows when the macro ends.

https://doc.rust-lang.org/1.7.0/book/macros.html#syntactic-r...

Re:Single Page Applications using Rust by quarantine on Tuesday August 11, 2020 @01:08PM (#24122723)
As a lot of less-than/greater-than tokens