Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allows to understand tree structure from the Visitor interface #119

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Dedrakot
Copy link

I need to create a tree structure of the future template model before request it. Visitor interface almost suits this purpose, but I need to know when I should return back to the parent node.

It will be great if it can be useful to someone else. If you think it's not, just close the pull request.

Additional notes:
I can add returnFromInvertedSection method or remove name argument from returnFromSection.

@agentgt
Copy link
Contributor

agentgt commented Dec 5, 2023

@Dedrakot are you still using JMustache and Visitor interface?

I'm curious how many are still using it because there are issues with it including as you noted knowing if you returned.

I'm going to tag a few others that I found by looking through old issues/prs that wanted / using the visitor pattern: @pmenhart @meirf @sandwwraith @samskivert

The problem with the Visitor pattern is that inevitable people really just want the tree and or its easier to navigate a tree (in this case AST).

This is because the Visitor pattern does not make it clear or easy to navigate in a different order.

Also Mustache has changed a lot over the years. There are tons of ambiguity when it comes to "dotted" keys, blocks (inheritance), parents, lambda sections etc. And I promise this will get worse as new features such as "filters" get added to the spec.

For example even if we add returnFromSection which on the surface seems like a reasonable request it will not work correctly or the way one expects when dealing with parents and blocks.

Example:

root.mustache:

{{< parent }}{{$a}}a{{/a}}{{/parent}}
{{$a}}b{{/a}}

parent.mustache:

{{$a}}c{{/a}}

If we traverse the nodes which $a should come first and how do we know if the $a comes from the parent partial, inside the partial call?

So you can see you need more than just returnFromSection but returnFromParentTemplate and returnFromParentBlock etc.

That is not to say the feature isn't useful for collecting key names its just that is about all its useful for at the moment.

The only thing I could see of use is if someone has a fairly flat model and wants to have some sort of UI that does completion or kind of validates which is I believe what @pmenhart is using the feature for.

So I want to see how people are using this because IMO if JMustache ever has a 2.0 I would love to remove it as one of the defining characteristics of JMustache over say Mustache.java is that it is fairly small.

@sandwwraith
Copy link

FTR, I don't use it anymore and don't even remember commenting some feature, sorry :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants