Java and Kotlin lambdas break the parser
See original GitHub issueHey, it’s me again 👋
I’m having an issue which breaks the code generator similarly to https://github.com/casid/jte/issues/112.
This time it’s happening with Java and Kotlin lambdas. Examples:
Lambdas.jte
!{var name = java.util.Optional.<String>ofNullable(null)}
${name.map((n) -> { "name: " + n }).orElse("")}
Which produces:
public static void render(gg.jte.TemplateOutput jteOutput, gg.jte.html.HtmlInterceptor jteHtmlInterceptor) {
var name = java.util.Optional.<String>ofNullable(null);
jteOutput.writeContent("\n");
jteOutput.writeUserContent(name.map((n) -> { "name: " + n );
jteOutput.writeContent(").orElse(\"\")}\n");
}
While this:
Lambdas.kte
!{val name: String = null}
${name?.let { "name: $it" } ?: ""}
Produces:
@JvmStatic fun render(jteOutput:gg.jte.TemplateOutput, jteHtmlInterceptor:gg.jte.html.HtmlInterceptor?) {
val name: String? = null
jteOutput.writeContent("\n")
jteOutput.writeUserContent(name?.let { "name: $it" )
jteOutput.writeContent(" ?: \"\"}\n")
}
Looks like the parser is accepting the first }
character as closing the ${}
block.
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Break out of lambda in kotlin - Stack Overflow
I am trying to add an very useful extension method to Java's InputStream class, since we know stream parsing requires several ...
Read more >Cant break out of lambda - Native - Kotlin Discussions
Hi Team, I am trying to add an very useful extension method to Java's InputStream class, since we know stream parsing requires several...
Read more >A complete guide to Kotlin lambda expressions
In this post, we'll dive into Kotlin's lambdas. We'll explore what they are, how they are structured, and where they can be used....
Read more >From zero to 10 million lines of Kotlin - Engineering at Meta
We're sharing lessons learned from shifting from Java to Kotlin. ... Although Java 8 adds support for lambdas and is available for Android, ......
Read more >Reading from the Command-Line in Kotlin - Sean Soper
We're going to call it the very originally named CommandLineParser . By bundling all of our parsing functionality into a single file we...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks!
Ahh, right. Forgot you’re generating Kotlin code. In this case you’re using
ContentType.Plain
anyways and there’s no output escaping. Thanks for clarifying!I’ll try to release a new version this weekend.