Repository navigation
fix: read comment markers in a text block as its content - #238
Closed
knutwannheden wants to merge 1 commit into
Closed
knutwannheden wants to merge 1 commit into
knutwannheden wants to merge 1 commit into
Conversation
A comment is an extra, so the lexer may match one wherever the text block expects a fragment. With equal precedence the longer match wins, and a comment runs to the end of its line or its `*/` where a fragment stops at the next `"` or `\`. So `//comment"""` read as a line comment that took the closing delimiter, and `/* "quoted" */` became a block comment inside the string. The fragment that excludes `"` and `\` takes precedence 1, as string_fragment does. The fragment that starts with `"` keeps precedence 0: a comment cannot start where it does, and at precedence 1 it would win over the closing `"""`.
|
Hi @knutwannheden, Thanks for working on this. This repository isn't actively maintained, so we have been maintaining a fork which has already integrated many improvements, meaning that the example you provide above already parses correctly there. If you encounter any issue switching to our fork, I would be happy to know what needs improving on our side. |
Author
|
@wetneb Thanks for letting me know! |
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.
A text block whose content holds
//or/*can lose its closing delimiter to a comment. This valid Java does not parse:Where the comment stops short of the delimiter, the file parses, but the string holds a comment node:
Comments are extras, so the lexer may match one wherever a text block expects a fragment. The fragment
/[^"\\]+/and the comments all have precedence 0, so the longer match wins. A comment runs to the end of its line or to its*/, while the fragment stops at the next"or\.The
[^"\\]+alternative of_multiline_string_fragmenttakesprec(1), asstring_fragmentalready does. That is why"//c\"x\""parses: lexical precedence outranks match length. The alternative that starts with"keeps precedence 0. No comment can start at a", and at precedence 1 it would beat the closing""".The new corpus test
text block with comment markersholds both inputs and fails without the change. All corpus tests pass with it.src/is not regenerated here.