-
Notifications
You must be signed in to change notification settings - Fork 50
Open
Description
Delete Position { column :: Int, line :: Int }
and replace it with Int
representing the position index from the beginning of the input. For String
, the position index would be in units of CodePoints.
Delete the updatePosString
and updatePosSingle
functions.
purescript-parsing/src/Text/Parsing/Parser/String.purs
Lines 179 to 200 in dbd9aae
-- | Updates a `Position` by adding the columns and lines in `String`. | |
updatePosString :: Position -> String -> String -> Position | |
updatePosString pos before after = case uncons before of | |
Nothing -> pos | |
Just { head, tail } -> do | |
let | |
newPos | |
| String.null tail = updatePosSingle pos head after | |
| otherwise = updatePosSingle pos head tail | |
updatePosString newPos tail after | |
-- | Updates a `Position` by adding the columns and lines in a | |
-- | single `CodePoint`. | |
updatePosSingle :: Position -> CodePoint -> String -> Position | |
updatePosSingle (Position { line, column }) cp after = case fromEnum cp of | |
10 -> Position { line: line + 1, column: 1 } -- "\n" | |
13 -> | |
case codePointAt 0 after of | |
Just nextCp | fromEnum nextCp == 10 -> Position { line, column } -- "\r\n" lookahead | |
_ -> Position { line: line + 1, column: 1 } -- "\r" | |
9 -> Position { line, column: column + 8 - ((column - 1) `mod` 8) } -- "\t" Who says that one tab is 8 columns? | |
_ -> Position { line, column: column + 1 } |
In updatePosString
there is an assumption that 1 tab = 8 spaces and there is no way for the library user to change that behavior. So I think updatePosString
has always been fundamentally broken.
We want to provide a way to track the line and column during the parse so that
- We can write indentation-sensitive parsers.
- We can report the line and column in a
ParseError
.
The Text.Parsing.Indent
module is used by some packages so we should try to keep it.
Metadata
Metadata
Assignees
Labels
No labels