@@ -152,7 +152,12 @@ prettyPrintToken (Number n) = either show show n
152152prettyPrintToken (HoleLit name) = "?" ++ name
153153
154154data PositionedToken = PositionedToken
155− { ptSourcePos :: P.SourcePos
155+ { -- | Start position of this token
156+ ptSourcePos :: P.SourcePos
157+ -- | End position of this token (not including whitespace)
158+ , ptEndPos :: P.SourcePos
159+ -- | End position of the previous token
160+ , ptPrevEndPos :: Maybe P.SourcePos
156161 , ptToken :: Token
157162 , ptComments :: [Comment]
158163 } deriving (Eq)
@@ -162,7 +167,13 @@ instance Show PositionedToken where
162167 show = prettyPrintToken . ptToken
163168
164169lex :: FilePath -> String -> Either P.ParseError [PositionedToken]
165−lex = P.parse parseTokens
170+lex f s = updatePositions <$> P.parse parseTokens f s
171+
172+updatePositions :: [PositionedToken] -> [PositionedToken]
173+updatePositions [] = []
174+updatePositions (x:xs) = x : zipWith update (x:xs) xs
175+ where
176+ update PositionedToken { ptEndPos = pos } pt = pt { ptPrevEndPos = Just pos }
166177
167178parseTokens :: P.Parsec String u [PositionedToken]
168179parseTokens = whitespace *> P.many parsePositionedToken <* P.skipMany parseComment <* P.eof
@@ -184,7 +195,9 @@ parsePositionedToken = P.try $ do
184195 comments <- P.many parseComment
185196 pos <- P.getPosition
186197 tok <- parseToken
187− return $ PositionedToken pos tok comments
198+ pos' <- P.getPosition
199+ whitespace
200+ return $ PositionedToken pos pos' Nothing tok comments
188201
189202parseToken :: P.Parsec String u Token
190203parseToken = P.choice
@@ -221,7 +234,7 @@ parseToken = P.choice
221234 , CharLiteral <$> parseCharLiteral
222235 , StringLiteral <$> parseStringLiteral
223236 , Number <$> parseNumber
224− ] <* whitespace
237+ ]
225238
226239 where
227240 parseLName :: P.Parsec String u String