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

Apache FreeMarker Language Support #2383

Closed
melloware opened this issue Mar 9, 2021 · 12 comments · Fixed by #2847
Closed

Apache FreeMarker Language Support #2383

melloware opened this issue Mar 9, 2021 · 12 comments · Fixed by #2847
Labels
feature-request Request for new features or functionality grammars
Milestone

Comments

@melloware
Copy link

Syntax highlighting for Apache Freemarker template language would be excellent.

See: https://freemarker.apache.org/

See: https://freemarker.apache.org/editors.html

See: https://freemarker.apache.org/docs/dgui_template_overallstructure.html

@melloware melloware changed the title FreeMarker Langauge Support FreeMarker Language Support Mar 9, 2021
@alexdima alexdima added feature-request Request for new features or functionality grammars labels Mar 11, 2021
@stolp
Copy link

stolp commented Apr 21, 2021

+1. I am also missing Freemarker support.

@jepsar
Copy link

jepsar commented Apr 21, 2021

Would be awesome. Subscribing!

@melloware
Copy link
Author

Also reported on the FreeMarker JIRA in case one of their devs wants to add the support: https://issues.apache.org/jira/browse/FREEMARKER-180

@FlipWarthog
Copy link

+1 as well. This would be a great addition.

@melloware melloware changed the title FreeMarker Language Support Apache FreeMarker Language Support Sep 14, 2021
@rawdog71
Copy link

rawdog71 commented Oct 6, 2021

I could use Freemarker and Velocity.

@jepsar
Copy link

jepsar commented Oct 6, 2021

@rawdog71 I would open a new ticket for Velocity if it doesn't exist yet.

@blutorange
Copy link
Contributor

blutorange commented Dec 12, 2021

We might need this too, I started taking a look at this. I made a first (not yet complete) draft based on the JavaCC grammar from FreeMarker. That grammar is pretty horrible though. Also, there's no the FreeMarker syntax, there's a couple of different syntaxes with some legacy options thrown into the mix a well (e.g. in ${...} mode [=...] is just plain text and vice versa, and there's also the legacy #{...}) And it's also got an "auto" mode where it tries to auto-detect the syntax...

Not sure yet, but I'm thinking legacy settings should be ignored, which leaves 2 expression (dollar and bracket) * 3 directive (auto, square bracket, angle bracket) syntaxes... which would result in 6 different language mode variations, hmm...


The existing code mirror highlighter I found nicely illustrates some of the complexity:

image


The Eclipse FreeMarker plugin implements auto mode, where you need to parse an arbitrary amount before you can establish the rules for highlighting. Note how the syntax highlighting changes, depending on the order of the lines (which don't have to be the first lines!):

image

image

And while the Eclipse plugin is definitely much better, even that plugin gets it wrong sometimes: Interpolation syntax is always set and never affects or determines the tag syntax, in auto mode the tag syntax is always determined by the first tag:

image

The above is wrong, if you evaluate that with FreeMarker in auto mode, you'll see that line 9 is evaluated and should thus have received syntax highlighting. Without the interpolation tag, synax highlighting seems to work:

image


There's also another FreeMarker feature that is completely impossible to implement (with monarch): highlighting for string interpolation. E.g. ${"a${1+2}b"} evaluates to a3b. But unlike JavaScript template literals, a ${ does not switch the tokenizer mode, instead it first and foremost parses it as a string, and then recursively parses the string content again. So the more you nest, the more escaping you need: ${"a"} evaluates to a, and so does ${"${\"a\"}"} and ${"${\"${\\\"a\\\"}\"}"} (and note that ${"${\"${\"a\"}\"}"} is a syntax error). In JavaScript

`${`${`${3}`}`}`

is valid. The solution here is to just not highlight interpolations in strings (which is what the CodeMirror and Eclipse highlighter are doing)

@melloware
Copy link
Author

I vote to ignore the legacy settings. No point in supporting something considered legacy only the newest FreeMarker syntax.

blutorange added a commit to blutorange/monaco-editor that referenced this issue Dec 21, 2021
alexdima added a commit that referenced this issue Jan 14, 2022
Implements #2383 Add syntax modes for FreeMarker template language
@alexdima alexdima added this to the January 2022 milestone Jan 14, 2022
@brendonparker
Copy link

Is there some documentation on how I might leverage this in monaco-editor?

I'm using react with the MonacoWebPackPlugin:

new MonacoWebpackPlugin({
    languages: ['xml', 'freemarker2'],
})

But it doesn't seem to get picked up

@blutorange
Copy link
Contributor

Haven't use the webpack plugin yet, so not sure about that, but doesn't add only include freemarker support?

Works on the playground if you specify the language when creating an editor

monaco.editor.create(document.getElementById('container'), {
	value: "",
	language: 'freemarker2'
});

image

@brendonparker
Copy link

Thanks. I think it is working. I was just expecting the non-freemarker xml to also syntax highlight.

@blutorange
Copy link
Contributor

Yeah would be great if that were possible, but (a) freemarker can be used for any text content, so we'd have to create a different language mode for each embedded language, and (b) there's no guarantee that the plain text without free marker directives and interpolations is valid in the embedded language, e.g. this is perfectly a legal freemarker document

<div>
${"<span"}></span>
</div>

That looks light a nightmare to write a highlighter for.

That's why I decided we should focus on highlighting freemarker syntax. But if anybody has an idea and/or wants to contribute, feel free to.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality grammars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants