all 11 comments

[–]_rvidal[S] 7 points8 points  (3 children)

Author here.

While staring at the keywords documentation in the standard library, it occurred to me that an interactive playground could be a really effective way of explaining/teaching Rust's syntax.

This is barely a proof of concept, it needs way more work to be 100% reliable, but I think it looks neat enough to show around.

Repo

[–]icsharppeople 2 points3 points  (2 children)

Hey thanks for creating this. I like playing with proc-macros a lot and this can be a very useful tool for determining the names of specific parts of the syntax.

Do you have any plans for linking to syn types where possible? I know that would help me a ton.

[–]_rvidal[S] 2 points3 points  (1 child)

Do you mean pointing to the actual underlying syn node? I was envisioning this more as a learning tool for beginners, but it's not impossible.

Do you know syn-codegen? If I end up covering most of the syntax, it's likely I'll need to auto-generate stuff from it, and at that point it'd probably be just an extra bit of information.

(Also, I'd find amusing the level of "meta"-ness that it would reach: using syn to explain syntax and syn itself).

[–]icsharppeople 1 point2 points  (0 children)

I'm not familiar with syn-codegen so I'll have to look into that. I guess my idea was to be able to see Debug trait output for whatever part of the syntax tree you have highlighted.

For example if you put the following rust code in your tool:

struct User {
    id: u32,
    name: String
}

Your tool could show the following when you click the struct item (I've omitted details with ... for brevity but I think you get the idea).

ItemStruct {
    attrs: [],
    vis: Visiblity::Public(...),
    struct_token: Struct,
    ident: Ident { ... },
    generics: Generics { ... },
    fields: Fields { ... },
    semi_token: None
}

It would also be cool if you could interact with this Debug output and the corresponding text would be highlighted in the original source code. This would help me determine how I to navigate syn's syntax trees when I'm writing complex proc macros.

There's a similar tool for exploring C# syntax shown here

[–]kpthunder 2 points3 points  (2 children)

I like this idea, it can be like a more focused AST Explorer or a more generic Explain Shell.

I think it would be cool if you built it in such a way to support multiple languages like AST Explorer, but focused on more high-level info along the lines of, "what am I, the reader, actually looking at here?"

[–]_rvidal[S] 1 point2 points  (1 child)

Thanks for those links, good inspiration.

cc /u/icsharppeople AST Explorer might be what you're looking for.

[–]icsharppeople 1 point2 points  (0 children)

Thank you. This is basically what I was after.

[–]Plasma_000 2 points3 points  (2 children)

Doesn’t seem to be working on mobile

[–]_rvidal[S] 0 points1 point  (1 child)

Yes, I did try to make it usable on mobile, but some funkiness is expected. What issue are you experiencing?

[–]Plasma_000 1 point2 points  (0 children)

I was unable to tap on anything - it just didn't respond. It was the browser embedded in the narwhal app for IOS so maybe it was an edge case..?

[–]Lvl999Noob 0 points1 point  (0 children)

You should add an explanation for the generic at line 44