Fix for the inconsistent internal parser state bug #54
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.
This code change fixes the following issues:
and makes the following pull requests superfluous:
findSubString
#37As described in issue #53, there's a bug in the
Elm.Kernel.Parser.findSubString
function,that leads to inconsistent internal parser positions where:
This code change fixes that bug, so that both offset and row/column are consistently positioned after the token.
There are two reasons why I chose the after token position and not the before token position:
multiComment
parser when using theNestable
modeThe real bug fix is on this line:
where we either return
-1
to signal the "subString not found" case, or the offset after the subString, which is stored in variabletarget
.So what about all the other changes?
First, I decided to rename the
newOffset
variable:It doesn't contain the new offset anymore (since we return either
-1
ortarget
), and I thought the name would be misleading now. Therefore I changed the name to "index", because it contains the result of theindexOf
function.In the
Parser.Advanced
module, there's a wrapper function for every Kernel function. The comment of thefindSubString
wrapper function has been wrong before this code change (see #37 "Fix comment infindSubString
"), and it was still wrong after the code change, so I changed it to document the fact, that we return the position after the subString:The wrapper functions hide the fact, that they are implemented in JavaScript rather than in Elm, from the rest of the module code. The rest of the code only uses the wrapper functions, just as if they had been implemented in Elm.
The only exception from this rule was a line where the
findSubString
Kernel function has been called directly, and I thought it was appropriate to change this line, too, to be consistent with the rest of the code, when we are modifying thefindSubString
function itself: