Skip to content

Commit

Permalink
fixes elm#54
Browse files Browse the repository at this point in the history
fixes elm#53

Fix bug in Elm.Kernel.Parser.findSubString
  • Loading branch information
pithub authored and rupertlssmith committed Feb 17, 2023
1 parent 02839df commit 6d655f1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/Elm/Kernel/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ var _Parser_consumeBase16 = F2(function(offset, string)

var _Parser_findSubString = F5(function(smallString, offset, row, col, bigString)
{
var newOffset = bigString.indexOf(smallString, offset);
var target = newOffset < 0 ? bigString.length : newOffset + smallString.length;
var index = bigString.indexOf(smallString, offset);
var target = index < 0 ? bigString.length : index + smallString.length;

while (offset < target)
{
Expand All @@ -130,5 +130,5 @@ var _Parser_findSubString = F5(function(smallString, offset, row, col, bigString
: ( col++, (code & 0xF800) === 0xD800 && offset++ )
}

return __Utils_Tuple3(newOffset, row, col);
return __Utils_Tuple3(index < 0 ? -1 : target, row, col);
});
4 changes: 2 additions & 2 deletions src/Parser/Advanced.elm
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ chompUntilEndOr str =
Parser <| \s ->
let
(newOffset, newRow, newCol) =
Elm.Kernel.Parser.findSubString str s.offset s.row s.col s.src
findSubString str s.offset s.row s.col s.src

adjustedOffset =
if newOffset < 0 then String.length s.src else newOffset
Expand Down Expand Up @@ -1125,7 +1125,7 @@ isAsciiCode =
findSubString "42" offset row col "Is 42 the answer?"
--==> (newOffset, newRow, newCol)
If `offset = 0` we would get `(3, 1, 4)`
If `offset = 0` we would get `(5, 1, 6)`
If `offset = 7` we would get `(-1, 1, 18)`
-}
findSubString : String -> Int -> Int -> Int -> String -> (Int, Int, Int)
Expand Down

0 comments on commit 6d655f1

Please sign in to comment.