openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2k stars 294 forks source link

XMLParser for jsp only works for jsp directives, but not for all jsp syntaxes #4306

Open Jenson3210 opened 1 week ago

Jenson3210 commented 1 week ago

According to this link and other sources online, there are multiple tags possible in jsp.

It seems the parser is failing to handle different tags than the tested directive.

See unit test added as reference using 2 examples from provided link.

Caused by: org.openrewrite.xml.XmlParsingException: Syntax error in scriptlet.jsp at line 4:5 no viable alternative at input '<%'.
    at org.openrewrite.xml.XmlParser$ForwardingErrorListener.syntaxError(XmlParser.java:120)
    ... 123 more
Caused by: org.antlr.v4.runtime.NoViableAltException
    at org.antlr.v4.runtime.atn.ParserATNSimulator.noViableAlt(ParserATNSimulator.java:2031)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.execATN(ParserATNSimulator.java:470)
    at org.antlr.v4.runtime.atn.ParserATNSimulator.adaptivePredict(ParserATNSimulator.java:396)
    at org.openrewrite.xml.internal.grammar.XMLParser.element(XMLParser.java:1060
Jenson3210 commented 1 week ago

Added a test case that shows the failure.

timtebeek commented 1 week ago

Thanks! I think this might be similar to this issue right?

We added some basic JSP parser support in March via

Looks like we'd need to extend that to cover additional syntax.

Jenson3210 commented 1 week ago

Ah! Now I know where we get these loggings from! Most likely related indeed! Did not consider this one to be the same as it was talking about mod cli.

Sorry for the double!

Jenson3210 commented 1 week ago

found https://github.com/wjase/jsp-parser/tree/master/src/main/antlr4/com/cybernostics/jsp/parser which could be usefull for a bases for the antlr processing

timtebeek commented 1 week ago

found https://github.com/wjase/jsp-parser/tree/master/src/main/antlr4/com/cybernostics/jsp/parser which could be usefull for a bases for the antlr processing

Nice find! One of those times where "last changed 7 years ago" feels right, and not problematic. 😅 Are you exploring an extension to our Antlr spec then?

Jenson3210 commented 1 week ago

Well, if I can't sleep I will have a look at this. It's haunting me 😅

But feel free to assign someone if there is no progress here. Started several times already and rollend back. It's not a piece of cake