Parser improvements - #9016
Open
Jenson3210 wants to merge 4 commits into
Open
Parser improvements#9016Jenson3210 wants to merge 4 commits into
Jenson3210 wants to merge 4 commits into
Conversation
added 4 commits
October 2, 2026 12:38
…=' in ADD/COPY paths
… template actions
Contributor
Author
Contributor
Author
|
@timtebeek @greg-at-moderne, I identified these issues while testing a parser on my end, no rush / direct need for it. It's just this ParseFailures cluttered my output. Feel free to close / cherry pick fixes that are worth picking. |
Contributor
Author
|
on the failed pipeline:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Parser fixes for failures found while analyzing a parse-failure report (
org.openrewrite.table.ParseFailures) across ~18 open source repositories.Docker (
rewrite-docker)CMD ["a", "b" , "c"]), so the printed output differed from the input. A newCommaPrefixmarker stores the whitespace before the comma on the preceding element, andDockerPrinterprints it back. Covers VOLUME, SHELL and the exec forms of CMD/ENTRYPOINT/RUN/HEALTHCHECK/COPY/ADD.=in ADD/COPY paths (ADD https://host/r?filepath=org/x.jar /dest) split the token, and ANTLR error recovery dropped text.sourcePathanddestinationPathnow acceptEQUALS, and tokens touching an=are regrouped into one argument. The lexer is unchanged, so ENV/LABEL/ARG behave as before.DockerParser.java/.interpare regenerated.JavaScript / TypeScript (
rewrite-javascript)decodeSourceBytes: aFF FEBOM is read as UTF-16LE,FE FFas UTF-16BE, and everything else as UTF-8 as before. Previously a UTF-16 file was read as UTF-8 and TypeScript reported diagnostic 1490 ("File appears to be binary").utf8for a UTF-16 file because the charset is detected after decoding. Printing is unaffected.JSON (
rewrite-json).json, template placeholders, a missing closing brace, ...) previously produced either an opaqueNullPointerExceptioninJsonParserVisitoror a mangled tree that failedrequirePrintEqualsInput.JsonParsernow records ANTLR syntax errors and, before the visitor runs, fails the file with aParseError:Syntax error in <path> at line L:C <msg>(plus a count of further errors).ParseError; before, some could still yield a document if it happened to print back identically.onErrornow receives oneJsonParsingExceptionper file. The existing suite (comments, single quotes, trailing commas, hex numbers) passes unchanged.YAML (
rewrite-yaml)UserData: !Base64followed by a newline andFn::Sub:,!workspace,!!python/object/apply:...) re-printed the first key with extra indentation. The tag suffix was cut with a hard-coded 2-character indent, so it only worked for a mapping nested exactly two deep (a root-level tag threwStringIndexOutOfBoundsException). The suffix now runs up to the last newline before the first key.findHelmTemplateEnd()replaces the single-line regex. It handles multi-line{{/* */}}comments, multi-line{{- ... }}actions and... -}}closers, and braces inside quoted strings (e.g."${2}"). A{{it cannot delimit falls back to the old regex. A standalone template line also no longer loses its leading/trailing whitespace, which caused print-idempotence failures.include ... | nindent), and non-YAML such as Jinja{% %}.Testing
rewrite-docker: 10 new tests (415 total, 0 failures).rewrite-json: parameterized syntax-error test over 9 inputs plus an empty-file test.rewrite-yaml: 8 tag tests and 13 Helm tests (737 total, 0 failures).rewrite-javascript:encoding.test.ts(UTF-16LE/BE, UTF-8 with and without BOM).rewrite-yamlagainst 5,809 YAML files containing{{from the cloned repos: parse + print-identical went from 5,744 to 5,782, non-idempotent from 4 to 0, parse errors from 61 to 27, with no regressions. All 16 tag-bearing files now round-trip.