Commit f5b00eb
Extend JSP parser to support scriptlets, expressions, declarations, and comments (#6054)
* feat(xml): Add lexer tokens for JSP scriptlets, expressions, declarations, and comments
Added new lexer tokens to XMLLexer.g4:
- JSP_COMMENT for <%-- comment --%>
- JSP_DECLARATION for <%! declarations %>
- JSP_EXPRESSION for <%= expressions %>
- JSP_SCRIPTLET for <% scriptlets %>
These tokens enable parsing of JSP-specific elements beyond the currently supported directives.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(xml): Update parser grammar to recognize JSP elements
Extended XMLParser.g4 to include grammar rules for:
- jspscriptlet for <% scriptlets %>
- jspexpression for <%= expressions %>
- jspdeclaration for <%! declarations %>
- jspcomment for <%-- comments --%>
Also updated content rule to include these new JSP elements as valid content types.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(xml): Add AST classes for JSP scriptlets, expressions, declarations, and comments
Added four new AST node classes to represent JSP elements:
- JspScriptlet for <% Java code %>
- JspExpression for <%= expression %>
- JspDeclaration for <%! declaration %>
- JspComment for <%-- comment --%>
Each class implements Xml and Content interfaces with proper prefix handling,
visitor pattern support, and toString implementations.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(xml): Implement parser visitor methods for JSP elements
Added visitor methods in XmlParserVisitor to handle parsing of:
- visitJspscriptlet() for <% scriptlets %>
- visitJspexpression() for <%= expressions %>
- visitJspdeclaration() for <%! declarations %>
- visitJspcomment() for <%-- comments --%>
Each method extracts the content from the JSP tags and creates the corresponding AST node.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(xml): Add visitor methods for JSP elements in XmlVisitor
Added visitor methods to handle traversal of new JSP AST nodes:
- visitJspScriptlet() for JspScriptlet nodes
- visitJspExpression() for JspExpression nodes
- visitJspDeclaration() for JspDeclaration nodes
- visitJspComment() for JspComment nodes
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* feat(xml): Add printer methods for JSP elements
Implemented printing support for new JSP AST nodes:
- visitJspScriptlet() prints <% content %>
- visitJspExpression() prints <%= content %>
- visitJspDeclaration() prints <%! content %>
- visitJspComment() prints <%-- content --%>
This ensures proper round-trip parsing and printing of JSP elements.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* test(xml): Add comprehensive tests for JSP element parsing
Added test cases for all new JSP elements:
- jspScriptlet() tests <% scriptlet %> parsing
- jspExpression() tests <%= expression %> parsing
- jspDeclaration() tests <%! declaration %> parsing
- jspComment() tests <%-- comment --%> parsing
- mixedJspElements() tests various JSP elements together
These tests verify proper parsing and round-trip printing of JSP-specific syntax.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(xml): Fix JSP parsing issues - preserve whitespace and allow in prolog
- Preserve all whitespace in JSP content (don't strip leading spaces)
- Allow JspDeclaration and JspComment as Misc items in prolog
- Fix lexer regex to properly exclude JSP comment pattern from scriptlet
- Update AST classes to implement Misc interface where appropriate
This allows JSP declarations to appear after DOCTYPE and before root element,
and preserves exact formatting of JSP content.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(xml): Update XmlParserVisitor to handle JSP elements in misc
Added handling for jspdeclaration and jspcomment in visitMisc method
so they can be properly parsed when appearing in the prolog after DOCTYPE.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(xml): Allow JSP directives and misc items to be interspersed in prolog
- Updated grammar to use prologContent rule that allows misc and jspdirective
in any order in the prolog
- Modified XmlParserVisitor to handle flexible prolog content ordering
- Adjusted test to reflect valid JSP structure
This allows more flexible JSP file structures where declarations and
directives can appear in any order after DOCTYPE.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* fix(xml): Prevent XmlDecl from being duplicated in prolog
XmlDecl implements both Xml and Misc interfaces, which was causing it
to be included twice in the prolog when processing prologContent.
Added check to skip XmlDecl when collecting misc items since it's
handled separately.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Update headers
* Apply best practices
* fix(xml): Revert prolog grammar changes to fix duplicate XmlDecl issue
The flexible prologContent approach was causing XmlDecl to be printed twice.
Reverted to the original prolog structure with misc* jspdirective* which
properly separates these elements. JSP declarations and comments are still
supported as Misc items within content areas.
Also moved JSP declaration in test to content area where it belongs.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
* Update headers & apply best practices
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent caa9585 commit f5b00eb
17 files changed
Lines changed: 1421 additions & 546 deletions
File tree
- rewrite-xml/src
- main
- antlr
- java/org/openrewrite/xml
- internal
- grammar
- tree
- test/java/org/openrewrite/xml
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
55 | 61 | | |
56 | 62 | | |
57 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
| 76 | + | |
| 77 | + | |
77 | 78 | | |
78 | 79 | | |
79 | 80 | | |
| |||
84 | 85 | | |
85 | 86 | | |
86 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
87 | 104 | | |
88 | 105 | | |
89 | 106 | | |
| |||
Lines changed: 16 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
149 | 149 | | |
150 | 150 | | |
151 | 151 | | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
152 | 168 | | |
Lines changed: 68 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
99 | 103 | | |
100 | 104 | | |
101 | 105 | | |
| |||
245 | 249 | | |
246 | 250 | | |
247 | 251 | | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
248 | 316 | | |
249 | 317 | | |
250 | 318 | | |
| |||
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
209 | 249 | | |
210 | 250 | | |
211 | 251 | | |
| |||
Lines changed: 13 additions & 1 deletion
Large diffs are not rendered by default.
0 commit comments